如何在 autohotkey 中表示 "backspace" 键

How to represent "backspace" key in autohotkey

我的键盘现在有问题,键在不应该的时候重复输入。我发现这个 autohotkey script online that ignores keystrokes if they're registered again in a very short timespan. The code works by listing all the broken keys contiguously in a string but I'm not sure how to list my backspace key. The documentation 表示退格键只是 backspace 但它对我不起作用。这是我目前所拥有的。

;List all your broken keys between quotes below. I.e. if your broken keys are g and f then the line below shoud be 
;brokenKeys := "gf"
brokenKeys := "fosbaituwrvlk"

;timepan in which subsequent keystrokes should be ignored.
fixOffset := 80

;These are typical values for a starter AHK script
#NoEnv
SendMode Input
SetWorkingDir %A_ScriptDir%

;This array will hold timers for each broken key
lastTimePressed := {}

;Create timer with current time for each broken key
Loop, Parse, brokenKeys
{
    lastTimePressed[A_LoopField] := A_TickCount
}

;lastTimePressed := A_TickCount

;Assign a hotkey handler for each broken key
Loop, Parse, brokenKeys
{    
    keyName := 
    Hotkey, $%A_LoopField%, HotKeyHandler 
}

HotKeyHandler:    
    pressedKey := SubStr(pressedKey,2)SubStr(A_ThisHotKey,2)    
    sinceLastPress := A_TickCount - lastTimePressed[pressedKey]
    if (sinceLastPress > fixOffset) { ;send the hijacked key only when sufficient time has passed
        lastTimePressed[pressedKey] := A_TickCount
        Send %pressedKey%
    }
return

编辑:我更新了我的代码。目前在我点击 backspace 后,退格键注册,但之后所有 brokenKeys 不再响应。从调试来看,pressedKey 变量似乎受到单击 backspace 的影响,因此 lastTimePressed[pressedKey]hotKeyHandler 函数中不起作用。

;List all your broken keys
brokenKeys := "f|o|s|b|a|i|t|u|w|r|v|l|k|'|backspace"

;timepan in which subsequent keystrokes should be ignored.
fixOffset := 80

;These are typical values for a starter AHK script
#NoEnv
SendMode Input
SetWorkingDir %A_ScriptDir%

;This array will hold timers for each broken key
lastTimePressed := {}

;Create timer with current time for each broken key
Loop, Parse, brokenKeys, |
{
    lastTimePressed[A_LoopField] := A_TickCount
}

;lastTimePressed := A_TickCount

;Assign a hotkey handler for each broken key
Loop, Parse, brokenKeys, |
{    
    keyName := 
    Hotkey, $%A_LoopField%, HotKeyHandler 
}

HotKeyHandler:
    pressedKey := SubStr(pressedKey,2)SubStr(A_ThisHotKey,2)
    sinceLastPress := A_TickCount - lastTimePressed[pressedKey]
    if (sinceLastPress > fixOffset) { ;send the hijacked key only when sufficient time has passed
        lastTimePressed[pressedKey] := A_TickCount
        if (pressedKey == "backspace"){
            Send {backspace}
        } else {
            Send %pressedKey%
        }
    }
return

这里的问题是解析循环可以接受一个分隔符来解析,否则它只会解析字符串中的单个字符。

;List all your broken keys between quotes below. I.e. if your broken keys are g and f then the line below should be 
;brokenKeys := "gf"
;brokenKeys := "fosbaituwrvlk"
brokenKeys := "f|o|s|b|a|i|t|u|w|r|v|l|k|backspace"

;timepan in which subsequent keystrokes should be ignored.
fixOffset := 80 ; MILLISECONDS

;These are typical values for a starter AHK script
#NoEnv
SendMode Input
SetWorkingDir %A_ScriptDir%

;This array will hold timers for each broken key
lastTimePressed := {}

;Create timer with current time and hotkey for each broken key
Loop, Parse, brokenKeys, |
{
    lastTimePressed[A_LoopField] := A_TickCount
    Hotkey, ~$%A_LoopField%, HotKeyHandler
}
 ; YOUR VERSION IS PARSING INDIVIDUAL CHARACTERS
 ; THIS ONE IS USING "|" TO SEPARATE THE KEY NAMES
 ; NOW YOU CAN USE A KEY NAME COMPOSED OF MORE THAN ONE CHARACTER
 ; JUST SEPARATE EACH ONE WITH A "|" IN THE 'BROKENKEYS' VARIABLE ABOVE.
 ; I ALSO INCLUDED BOTH LOOP ACTIONS IN ONE LOOP, INSTEAD OF TWO.
 ; WHICH SAVES TIME IN LOADING, ALBEIT MARGINALLY.
Return
 
 HotKeyHandler:    
    pressedKey := SubStr(pressedKey,2)SubStr(A_ThisHotKey,2)    
    sinceLastPress := A_TickCount - lastTimePressed[pressedKey]
    if (sinceLastPress > fixOffset) { ;send the hijacked key only when sufficient time has passed
        lastTimePressed[pressedKey] := A_TickCount
        Send %pressedKey%
    }
return

设法从 here

获得解决方案
;List all your broken keys
brokenKeys := "f|o|s|b|a|i|t|u|w|r|v|l|k|Backspace"

;timepan in which subsequent keystrokes should be ignored.
fixOffset := 80

;These are typical values for a starter AHK script
#NoEnv
SendMode Input
SetWorkingDir %A_ScriptDir%

;This array will hold timers for each broken key
lastTimePressed := {}

;Create timer with current time for each broken key
Loop, Parse, brokenKeys, |
    lastTimePressed[A_LoopField] := A_TickCount

;lastTimePressed := A_TickCount

;Assign a hotkey handler for each broken key
Loop, Parse, brokenKeys, |
{    
    keyName := 
    Hotkey, $%A_LoopField%, HotKeyHandler 
}
Return
HotKeyHandler:    
    pressedKey := SubStr(A_ThisHotKey,2) ;<<<< corrected  
    sinceLastPress := A_TickCount - lastTimePressed[pressedKey]
    if (sinceLastPress > fixOffset) { ;send the hijacked key only when sufficient time has passed
        lastTimePressed[pressedKey] := A_TickCount
        Send {%pressedKey%} ;<<<< corrected
    }
return