AutoHotkey - 检测AltGr的双击

时间:2017-07-05 13:48:57

标签: autohotkey double-click

我想检测双按 AltGr

根据文件:

; Example #4: Detects when a key has been double-pressed (similar to double-click).
; KeyWait is used to stop the keyboard's auto-repeat feature from creating an unwanted
; double-press when you hold down the RControl key to modify another key.  It does this by
; keeping the hotkey's thread running, which blocks the auto-repeats by relying upon
; #MaxThreadsPerHotkey being at its default setting of 1.
; Note: There is a more elaborate script to distinguish between single, double, and
; triple-presses at the bottom of the SetTimer page.
~RControl::
if (A_PriorHotkey <> "~RControl" or A_TimeSincePriorHotkey > 400)
{
    ; Too much time between presses, so this isn't a double-press.
    KeyWait, RControl
    return
}
MsgBox You double-pressed the right control key.
return
实际上是 LControl &amp; RALT 。因此,对于 AltGr ,脚本应该是这样的:

~LControl & RAlt::
    if (A_PriorHotkey <> "~LControl & RAlt" or A_TimeSincePriorHotkey > 400)
    {
        click
        KeyWait, LControl & RAlt
        return
    }
    click 2
    return

但是当我尝试加载此脚本时,AutoHotkey会出错:

enter image description here

也许有办法为键组合制作别名。

1 个答案:

答案 0 :(得分:0)

如评论中所述,KeyWait一次只能等待一个(不是热键)。您只需要等待RAlt被释放,而无需等待LCtrl和RAlt的组合。

这有效:

~LControl & RAlt::
    if (A_PriorHotkey <> "~LControl & RAlt" or A_TimeSincePriorHotkey > 400)
    {
        KeyWait, RAlt
        return
    }
    MsgBox Double-click
    return

但是,在这种情况下,仅使用KeyWait(结合默认的#MaxThreadsPerHotkey设置1)来防止按键重复激活热键。您可以删除KeyWait,它仍会检测到两次按动。但是如果按住AltGr直到它自动重复,它也会激活。

请注意,在您的情况下,双击热键将单击三次:第一次按一次,第二次按附加两次。

>

如果您只想将AltGr用作鼠标按钮并允许双击,则只需<^RAlt::Click

如果要根据是单击还是双击执行两种不同的操作,则必须延迟对第一次单击的响应,直到知道是否有第二次单击为止。例如:

<^RAlt::
    KeyWait RAlt
    KeyWait RAlt, D T0.4
    if ErrorLevel
        MsgBox Single
    else
        MsgBox Double
    return