AutoHotkey-检测双击AltGr

问题描述 投票:2回答:1

我想检测对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

AltGr实际上是LControlRAlt的组合。因此,对于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

也许有一种方法可以为组合键起别名。

autohotkey double-click
1个回答
0
投票

如评论中所述,KeyWait一次只能等待一个key(不是热键)。您只需要等待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
© www.soinside.com 2019 - 2024. All rights reserved.