Hold down key while mouse button is down

Get help with using AutoHotkey and its commands and hotkeys
pocpoc
Posts: 2
Joined: 21 Apr 2017, 05:05

Hold down key while mouse button is down

21 Apr 2017, 05:12

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
User avatar
Nextron
Posts: 1003
Joined: 01 Oct 2013, 08:23
Location: Netherlands OS: Win7 x64 AHK: Unicode x32

Re: Hold down key while mouse button is down

21 Apr 2017, 06:07

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
The more I know:
The more I know,
I know nothing.
pocpoc
Posts: 2
Joined: 21 Apr 2017, 05:05

Re: Hold down key while mouse button is down

21 Apr 2017, 06:22

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 :)

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], ktbjx, newbieforever, Sabestian Caine, Yahoo [Bot] and 13 guests