使用自动热键进行自动移位

使用自动热键进行自动移位

我想尝试一下自动换档功能。也就是说,如果任何字母数字键按下的时间超过某个计时器,就会自动应用“换档”。

我猜想有人已经在 autohotkey 上实现了这个或非常相似的功能。但是,我是 autohotkey 的新手,很难找到相关示例。有人可以给我指出这些示例或给我一些入门提示吗?

答案1

; create an array/object of the keys you want shift:
Keys := ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","1","2","3","4","5","6","7","8","9","0"]

; create a hotkey once for each key in this object, using a For-Loop:
For each, key in Keys
    Hotkey, $%key%, Shift_Key ; the $ prefix forces the keyboard hook to be used
return

Shift_Key:
    ThisHotkey := StrReplace(A_ThisHotkey, "$") ; remove the $ prefix 
    KeyWait, %ThisHotkey%, T0.3 ; wait max. 0.3 seconds for the key to be released
    If (ErrorLevel) ; if the command timed out (long press, the key is still pressed after 0.3 seconds)
        SendInput, +%ThisHotkey% ; "shift" it
    else
        SendInput, %ThisHotkey%
    KeyWait, %ThisHotkey% ; don't repeat the action before the key is released
return

https://autohotkey.com/docs/Objects.htm

https://autohotkey.com/docs/commands/For.htm

https://autohotkey.com/docs/commands/Hotkey.htm

https://autohotkey.com/docs/commands/KeyWait.htm

相关内容