Rotareti
Rotareti

Reputation: 53933

Autohotkey. Hold two buttons and tap another to increase volume

I got stuck building an ahk shortcut script to increase / decrease Volume. The idea was to hold down LAlt+LShift and tap F12 to increase one step per tap. The order in which LAlt and LShift are pressed shouldn't matter.

I came up with this so far:

!+::
    While (GetKeyState("LShift","P")) and (GetKeyState("LAlt","P"))
    {
        F12::Send {Volume_Up}
    }
Return

But somehow it increases the volume on holding LAlt and taping F12. LShift gets igronred..

What's wrong with that...

Upvotes: 0

Views: 223

Answers (1)

phil294
phil294

Reputation: 10872

This

    F12::Send {Volume_Up}

isn't a command, it's a hotkey assignment. You cannot use it within executable context. It is actually the short form for:

F12::
send {volume_up}
return

You wouldn't wanna have a return somewhere in between the lines which should be executed, would you.

As can be read in the documentation, you can only combine two Hotkeys for an action easily, like a & b::msgbox, you pressed a and b. E.g. for a,b AND c, you'd need some workaround like the crossed out, old answer below.

BUT you can add as many modifiers to your hotkey as you want. Modifiers are ! alt, + shift, # win and so on (please have a look @ http://ahkscript.org/docs/Hotkeys.htm#Symbols).

So you can simply use

<!+F12::send {volume_up}

-

So, your aim is simply to have volume_up be fired when three Hotkeys are being pressed. You can achieve it like this:

#if getKeyState("LShift", "P")
    *<!F12::send {volume_up}
#if

or

*<!F12::
    if(getKeyState("LShift","P"))
        send {volume_up}
return

For the meaning of * and < and other possible modifiers, see http://ahkscript.org/docs/Hotkeys.htm#Symbols


Your approach wasn't too bad. It would have worked if you had used the Hotkey command instead of an actual hotkey assignment. Still that would have been unneeded work

Upvotes: 2

Related Questions