简体   繁体   中英

Multiple functions on one hotkey (key hold down and release)

I'm trying to build script which lowers volume once when hotkey is held down and after key is released volume is set back to normal/previous volume. This same key (when hold down) should also send input like normal key.

Case:

  • Hold down w -key volume is lowered only once and w is sent multiple times (like normal key hold)
  • Release w -key volume is set back to normal

Here is my current script which works for volume as described:

$w::
SoundGet OldVolume
SoundSet, -20
KeyWait, w
w UP::SoundSet OldVolume
return

I did try to make loop to send w when hold down but then volume adjustment did not work anymore.

I'm not sure if this multiaction is even possible where key press should do something only once and something else multiple times. Any help appreciated!

You'll be fine with just specifying the ~ hotkey modifier.
It's going to make the hotkey not consume the key when used. So the key will retain its normal functionality as well.

And also, you don't need the w UP hotkey variant, just set the old sound level under the KeyWait command.

Here's your complete script:

~w::
    SoundGet, OldVolume
    SoundSet, -20
    KeyWait, w
    SoundSet, OldVolume
return

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM