34

I'm not stupid... really. How do you map a key SEQUENCE (ie: Ctrl + Q , F) in AutoHotKey.

I've got Ctrl + Q down:

^q::

I've even got F:

f::

The examples in the help files even show how to do two keystrokes in a row:

Numpad0 & Numpad1::

But it just will not work with:

^q & f ::

Or any of these either:

LCtrl & q & f::
^q & ^f::
^q^f::
^qf::

How do I accomplish a Key SEQUENCE triggering something, when one of those keys is the Ctrl key? I looked into using a HOTSTRING instead, but couldn't work out how to include the Ctrl character, in that context!

Jasper
  • 2,166
  • 4
  • 30
  • 50
Joshua
  • 6,643
  • 15
  • 55
  • 76

5 Answers5

30

Alright; The answer seems to be:

^q::
Input Key, L1
if Key=f
...some code here...
return
Joshua
  • 6,643
  • 15
  • 55
  • 76
  • 1
    I've handled this in an effective but ugly way in the past. I like your approach better, and have combined it with the Progress command to make nice key-sequence menus, such as the one I use to launch browsers **[here](https://gist.github.com/ajkerrigan/a0e54dbdd5fb3dea5113)**. Thanks for a better way! – ajk Jul 13 '15 at 16:21
  • 1
    This messed up my ctrl key after a few tries, so for example I couldn't press ctrl-shift-escape anymore – BornToCode Aug 19 '15 at 15:43
5

In case someone's looking for a similar thing, but actually want CtrlQ + CtrlF and only if Ctrl is held throughout (so, to some, this might seem like CtrlQ + F), then here's how to do that:

$Ctrl::Send {Ctrl Down}
$Ctrl UP::
    ChordIsBroken := True
    Send {Ctrl Up}
    Return
^q::
    ChordIsBroken := False
    Input, OutputVar, L1 M
    If (!ChordIsBroken && Asc(OutputVar) = 6)
    {
        MsgBox "Hello, World!"
    }
    Else
    {
        SendInput %OutputVar%
    }
    Return

See https://superuser.com/a/725303/145431 for my explanation.

Community
  • 1
  • 1
Andrew Cheong
  • 29,362
  • 15
  • 90
  • 145
2

Or you can do it like this:

q & f::
    if GetKeyState("Control") {
        ; Do something
        return
    }
    return

I think this is a bit more readable than using Input Key, L1 as in above.

Ciantic
  • 6,064
  • 4
  • 54
  • 49
  • 7
    The ampersand notation requires both keys to be held down at the **same** time. In caps, the OP specifies "sequence" so this answer won't work. – horta May 20 '14 at 15:20
1

This catches CTRL+F. If Q is held down at that moment, your code fires.

^f::
    If GetKeyState("q", "p") {
        MsgBox test
    } Else {
        Send ^f
    }
return
lance
  • 16,092
  • 19
  • 77
  • 136
0

AutoHotkey v1:

#Requires AutoHotkey v1.1.33

^q:: ctrl_q := true ; assign the Boolean value "true" or "1" to this variable
^q up:: ctrl_q := false

; The #If directive creates context-sensitive hotkeys:

#If (ctrl_q) ; If this variable has the value "true"

    ^a:: MsgBox, Ctrl + Q + A
    
    ^b:: MsgBox, Ctrl + Q + B

    ; ...
    
#If

AutoHotkey v2:

#Requires AutoHotkey v2.0

^q:: ctrl_q := true ; assign the Boolean value "true" or "1" to this variable
^q up:: ctrl_q := false

; The #HotIf  directive creates context-sensitive hotkeys:

#HotIf (ctrl_q := true ) ; If this variable has the value "true"

    ^a:: MsgBox "Ctrl + Q + A"
    
    ^b:: MsgBox "Ctrl + Q + B"

    ; ...
    
#HotIf
user3419297
  • 9,537
  • 2
  • 15
  • 24