长按 AHK 替代键

Dan*_*elM 5 autohotkey key alternate

我有一个键盘,其中这些箭头(小于/大于)字符作为 Y 和 X 上的备用键。

键盘

让我们重点关注本例中的 X 键。

默认情况下,替代字符 > 当然是通过 AltGr + X 触发的。

但我想通过简单地长按 X 来触发它,以加快速度,并且不需要第二只手或手指。

到目前为止,我从其他帖子中得到了以下内容:

$x::
    KeyWait, x, T0.2

    if (ErrorLevel)
        Send > ;long

    else {
        KeyWait, x, D T0.2

        if (ErrorLevel)
            Send x ;single
    }

    KeyWait, x
return
Run Code Online (Sandbox Code Playgroud)

这基本上可以工作,但有一个主要缺陷:正常的单键按下现在需要太多时间来写入正常的 X 字符。

例如,如果您写得很快,比如“exchange”,您最终会得到“echxange”之类的内容,因为发送 X 需要太多时间。

那么如何修改这个脚本来解决这个问题呢?我的想法是发送一个普通的 X 并在注册了 {X Up} 后中止整个脚本。所以在{X Up}之后他将不再等待。

或者还有其他想法吗?

谢谢。

Yan*_*ane 5

这是一个计算按键持续时间的解决方案,缺点是您总是必须释放按键才能获得所需的输入。这意味着您无法按住 x 来输入 xxxxxxxx。

$x::
    startTime := A_TickCount ;record the time the key was pressed
    KeyWait, x, U ;wait for the key to be released
    keypressDuration := A_TickCount-startTime ;calculate the duration the key was pressed down
    if (keypressDuration > 200) ;if the key was pressed down for more than 200ms send >
    {
        Send > 
    }
    else ;if the key was pressed down for less than 200ms send x
    {
         Send x 
    }

return
Run Code Online (Sandbox Code Playgroud)