In Autohotkey, I know you can use "KeyWait" to wait for a key to be pressed or released, but what can I do if I want to be able to wait for either of two keys to be released?

I found this on the web, but it is when you want to wait for either of two keys to be pressed

LButton & XButton1:: Keywait, r Keywait, LAlt SendInput {ShiftDown} SendInput {v Down} SendInput {v Up} SendInput {Shift Up} Input, UserInput,v,{LButton}{XButton1} ;v is if you want input to be visible if ErrorLevel=EndKey:LButton { theFunctionIrunAlltheTime() Return } else if ErrorLevel=EndKey:XButton1 { theFunctionIrunAlltheTime() Return } 

No matter which of those Buttons is release I want to do the same, I think the example above works only with letters, not with Buttons, but the important thing here is that by the time the script is run, LButton n XButton1 are already pressed and I want in the middle of the subroutine to detect when any of them is released, any idea please??? thanks adavanced.

2 Answers

Try also this:

~LButton & XButton1:: SetTimer detect_key_released, 50 ; do sth return detect_key_released: If !GetKeyState("LButton", "P") { SetTimer detect_key_released, off MsgBox LButton released return } If !GetKeyState("XButton1", "P") { SetTimer detect_key_released, off MsgBox XButton1 released return } return 
1
While GetKeyState("LButton") && GetKeyState("XButton1") Sleep 10 ; msg to user assumes only one or the other was released... MsgBox % (GetKeyState("LButton") ? "XButton1" : "LButton") " Released" 
1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy