Autohotkey. Hold two buttons and tap another to increase volume

此生再无相见时 提交于 2019-12-11 22:41:29

问题


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...


回答1:


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



来源:https://stackoverflow.com/questions/33314898/autohotkey-hold-two-buttons-and-tap-another-to-increase-volume

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