2
votes

I want to detect double press on AltGr.

According to documentation:

; 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 is actually a combination of LControl & RAlt. So, for AltGr, script should be something like this:

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

But when I try to load this script, AutoHotkey gives an error:

enter image description here

Maybe there is a way to make an alias for key combinations.

1
Keywait can't be used with multiple keys. Here are a few forum posts which may help. (1, 2, 3) - Stevoisiak

1 Answers

0
votes

As mentioned in the comments, KeyWait can only wait on one key (not hotkey) at a time. You only need to wait for RAlt to be released, not the combination of LCtrl and RAlt.

This works:

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

However, in this case KeyWait is only being used (in combination with the default #MaxThreadsPerHotkey setting of 1) to prevent key-repeat from activating the hotkey. You can remove KeyWait and it will still detect double-presses; but it will also activate if you hold AltGr down until it auto-repeats.

Note that in your case, double-pressing the hotkey would click three times: once on the first press and an additional two times on the second press.

If you just want to use AltGr as a mouse button and allow double-click, all you need is <^RAlt::Click.

If you want to perform two different actions depending on whether it is a single or double click, you must delay the response to the first click until you know whether there's a second click. For example:

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