Page 1 of 1

Hold down key while mouse button is down

Posted: 21 Apr 2017, 05:12
by pocpoc
I want a key to be pressed while I hold ctrl+mouseClick, but it only presses it once.

Code: [Select all] [Download] GeSHi © Codebox Plus

^LButton::Send {Volume_Up} ; this sends Volume_Up once when I hold the mouse


However, when I do the same with a keyboard key, it works fine.

Code: [Select all] [Download] GeSHi © Codebox Plus

^Up::Send {Volume_Up} ; this sends Volume_Up once when I press the key then continuously (the normal behaviour for a direct keypress)


Thank you for your help,
pocpoc

Re: Hold down key while mouse button is down

Posted: 21 Apr 2017, 06:07
by Nextron
Keyboard keys have a native key repeat, so holding a button down and releasing it results in the events: down-down-down-down-up; repeatedly triggering the hotkey. Mouse button don't have that, so you need to mimic it:

Code: [Select all] [Download] GeSHi © Codebox Plus

^LButton::
Loop {
Send {Volume_Up}
Sleep 200
}Until !GetKeyState("LButton","P")
Return

Re: Hold down key while mouse button is down

Posted: 21 Apr 2017, 06:22
by pocpoc
I suspected that the intrinsic behaviour was different, thank you!

Interestingly enough however, it doesn't behave the same with Volume_Up and with Volume_Down.
With Volume_Up the volume steadily increases but with Volume_Down it starts normally then suddenly accelerates.

EDIT: This has actually nothing to do with autohotkey but is the behaviour of the Volume_Down key on my computer. After more than 6 fast presses, the volume step changes from 2 to about 10. Funny that this only happens with Volume_Down though. I guess it's better to be able to quickly turn the volume down than up :)