To make multiple KeyWait independent

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
dwoss
Posts: 2
Joined: 16 Oct 2021, 20:31

To make multiple KeyWait independent

Post by dwoss » 16 Oct 2021, 20:40

Code: Select all

LButton::
funcAAA()
Send, {LButton down}
KeyWait LButton
Send, {LButton up}
funcBBB()
Return

LCtrl::
funcCCC()
Send, {LCtrl down}
KeyWait LCtrl
Send, {LCtrl up}
funcDDD()
Return
If you have the above description
When a string is selected by dragging and the {LCtrl} key is pressed to copy the string with ^C
If the {LCtrl} key is pressed while the string is selected by dragging, the string will remain dragged while the {LCtrl} key is pressed even if the left mouse button is released.

I think this is due to the specification that when multiple key waits are performed, it waits until all of those keys are released.
How can I rewrite it so that the timing of each up is independent (immediately after the key is released)?

(Translated from Japanese to English by DeepL)

Rohwedder
Posts: 7551
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: To make multiple KeyWait independent

Post by Rohwedder » 17 Oct 2021, 02:30

Hallo,
try:

Code: Select all

LButton::
IF GetKeyState(A_ThisHotkey)
	Return
funcAAA()
Send, {LButton down}
Return
~LButton Up::funcBBB()

LCtrl::
IF GetKeyState(A_ThisHotkey)
	Return
funcCCC()
Send, {LCtrl down}
Return
~LCtrl Up::funcDDD()
This was my test script:

Code: Select all

q::
IF GetKeyState(A_ThisHotkey)
	Return
SoundBeep, 4000, 20
Send, {q Down}
Return
~q Up::SoundBeep, 2000, 20
w::
IF GetKeyState(A_ThisHotkey)
	Return
SoundBeep, 1000, 20
Send, {w Down}
Return
~w Up::SoundBeep, 500, 20

dwoss
Posts: 2
Joined: 16 Oct 2021, 20:31

Re: To make multiple KeyWait independent

Post by dwoss » 17 Oct 2021, 06:40

Thank you!
But I had to do what I wrote below, otherwise Ctrl seemed to stay pressed.

Code: Select all

~LCtrl up::
Send, {LCtrl Up}
funcDDD()
Return

Rohwedder
Posts: 7551
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: To make multiple KeyWait independent

Post by Rohwedder » 17 Oct 2021, 09:29

True! Had surprised me.

Post Reply

Return to “Ask for Help (v1)”