写了一个用空格键当修饰键的 ahk 脚本,打字的时候不用移动手就能直接按到方向, backspace 之类的常用按键

2017-04-29 12:37:05 +08:00
 cy18

按住空格键大概 0.1 秒之后,空格键变成修饰键,然后可以用 edsf 控制方向,wr 控制 home 跟 end,cv 控制 backspace 跟 del,其他键还是照常工作。根据个人习惯可以改其他快捷键。

用了这套快捷键之后根本停不下来,完全不用移动手腕就可以控制方向,删除打错的字符。在不支持 vim 命令的编辑器里面尤其方便。相比于用 ctrl,alt,shift 做快捷键,空格键更方便,大拇指直接按下去就可以了。唯一的问题就是按住空格不放不能重复输入空格了。我个人感觉这个基本没有影响。

网上有一个类似的脚本,不过打字比较快的时候容易出问题,我重写了一个改进版的,打字快的时候基本不会出错。 这是我的第一个 ahk 脚本,有什么需要改进的地方,或者 ahk 高手看到有什么函数用错的地方,都欢迎提出来。

;
; AutoHotkey Version: 1.x
; Language:       English
; Platform:       Win9x/NT
; Author:         cy18 <thecy18@gmail.com>
;
; An improved script to use space as modifier
; In normal cases, if space is pressed for more than 0.1 second, it becomes a modifier, this time could be modified in the script
; If no other keys are pressed during space is pressed, a space is output when space is released
; Severial tunes are made so that the script works well when typing in fast speed
; Note that repeating space no longer works

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

AnyKeyPressedOtherThanSpace(mode = "P") {
    keys = 1234567890-=qwertyuiop[]\asdfghjkl;'zxcvbnm,./
    Loop, Parse, keys
    {        
        isDown :=  GetKeyState(A_LoopField, mode)
        if(isDown)
            return True
    }   
    return False
}
 
Space Up::
    space_up := true
    Send, {F18}
    return
Space::
    if AnyKeyPressedOtherThanSpace(){
        SendInput, {Blind}{Space}
        Return
    }
    space_up := False
    inputed := False
    input, UserInput, L1 T0.1, {F18}
    if (space_up) {
        Send, {Blind}{Space}
        return
    }else if (StrLen(UserInput) == 1){
        Send, {Space}%UserInput%
        return
    }
    while true{
        input, UserInput, L1, {F18}
        if (space_up) {
            if (!inputed){
                Send, {Blind}{Space}
            }
            break
        }else if (StrLen(UserInput) == 1) {
            inputed := True
            StringLower, UserInput, UserInput
            if (UserInput == "e")
                Send, {Blind}{Up}
            else if (UserInput == "d")
                Send, {Blind}{Down}
            else if (UserInput == "s")
                Send, {Blind}{Left}
            else if (UserInput == "f")
                Send, {Blind}{Right}
            else if (UserInput == "w")
                Send, {Blind}{Home}
            else if (UserInput == "r")
                Send, {Blind}{End}
            else if (UserInput == "c")
                Send, {Blind}{BS}
            else if (UserInput == "v")
                Send, {Blind}{DEL}
            else
                Send, {Blind}%UserInput%
        }
    }
    return
5351 次点击
所在节点    分享创造
21 条回复
cy18
2018-06-10 00:18:46 +08:00
@xxxcjr 我理解错你的意思了- -
我试了一下,RAlt 确实也挺方便的- -而且我现在大部分的快捷键都是在左手,所以用 RAlt 完全不会有冲突的感觉……
实现起来也方便,不用像空格这样加一堆东西,直接用 AHK 现成的功能就能实现。
等有空了我也搞一个这种试试

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/358093

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX