Bind commands to key-up and key-down in AutoHotkey

3

1

I have written two functions in an AutoHotkey script: fun1() and fun2(). I now need to bind fun1() to when Pause is pressed down, and bind fun2() to when Pause is released.

As an example, I would press and hold Pause to hide all windows, and release Pause to restore all windows. (This example is not my actual objetive).

How can I do that in AutoHotkey?

Malabarba

Posted 2010-11-08T06:06:06.050

Reputation: 7 588

Answers

4

You could compile your .ahk scripts as .exe. Then have

Pause::C:\fun1.exe    
Pause Up::C:\fun2.exe

More info on .akh to .exe: autohotkey- ahk2exe

outsideblasts

Posted 2010-11-08T06:06:06.050

Reputation: 6 297

No need to add Down since its the default trigger. Only Up must be specified – nixda – 2014-09-23T18:37:08.753

Actually, compiling them is unnecessary. I already defined them as functions. My question regarded specifically to the key up/down syntax. I wasn't finding it in the manual, so I asked here. Eventually I found a couple examples online, and it's exactly what you said except there's a blank space between "pause" and "up/down". – Malabarba – 2010-11-09T11:12:07.620

1

You can accomplish the desired functionality with this code:

pause::
    fun1()
    keyWait, pause
    fun2()
return

If you are dealing with subroutines instead, use this:

pause::
    gosub, sub1
    keyWait, pause
    gosub, sub2
return

adaaaam

Posted 2010-11-08T06:06:06.050

Reputation: 329