【问题标题】:AutoHotkey - Detect double press of AltGrAutoHotkey - 检测 AltGr 的双击
【发布时间】:2019-09-28 09:12:12
【问题描述】:

我想检测 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 会报错:

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

【问题讨论】:

  • Keywait 不能与多个键一起使用。这里有一些论坛帖子可能会有所帮助。 (1, 2, 3)

标签: autohotkey double-click


【解决方案1】:

如 cmets 中所述,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 直到它自动重复,它也会激活。

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

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-05-27
    • 2015-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多