AutoHotKey key SEQUENCE, not just single-key hotkey

落花浮王杯 提交于 2019-11-26 16:31:33

问题


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!


回答1:


Alright; The answer seems to be:

^q::
Input Key, L1
if Key=f
...some code here...
return



回答2:


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.




回答3:


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.




回答4:


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


来源:https://stackoverflow.com/questions/2096253/autohotkey-key-sequence-not-just-single-key-hotkey

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!