实施 Autoshift 时 KeyWait 行为异常

实施 Autoshift 时 KeyWait 行为异常

我想使用 AHK 实现自动移位,我使用了这个脚本:https://superuser.com/a/1396278/47625

; 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

一开始这似乎很有效,但是有一个问题。当你打字速度很快时,它会以某种方式用最后输入的字母覆盖前面的字母:

我在 300 毫秒内写入:这个结果是:ssss

有什么办法可以解决这个问题吗?

答案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
    Hotkey, ~$%key% Up, Up_Key
}
return

Shift_Key:
    ThisHotkey := StrReplace(A_ThisHotkey, "$") ; remove the $ prefix 
    If (A_PriorHotKey = "$" ThisHotKey)
    {
        Text := ThisHotkey
        StringUpper, Text, Text
        ToolTip %Text%
        KeyWait, %ThisHotkey%           
        SendInput, {BS}+%ThisHotkey% ; "shift" it
        ToolTip
    }
    else
        SendInput, %ThisHotkey%
return

Up_Key:
return

相关内容