How to interupt KeyWait?

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
LogicNg
Posts: 20
Joined: 17 Mar 2021, 05:39

How to interupt KeyWait?

Post by LogicNg » 06 Apr 2021, 04:02

Code: Select all

F11::
	KeyWait, F11, U
	Msgbox, hi
return
I want to edit this code so that when ESC is pressed before F11 is released it does nothing, any idea?
lexikos
Posts: 9592
Joined: 30 Sep 2013, 04:07
Contact:

Re: How to interupt KeyWait?

Post by lexikos » 07 Apr 2021, 03:28

No can do (with KeyWait).

But you can do this:

Code: Select all

F11 up::  ; when F11 is released
    if (A_PriorKey = "F11")  ; if the last pressed key was F11
        MsgBox, hi
return
or this:

Code: Select all

F11 & Esc::return  ; when Esc is pressed in combination with F11, do nothing
F11 up::MsgBox, hi  ; if F11 is used on its own...
"up" is optional in this case since using F11 as a prefix key makes it act on release, but it adds clarity.
User avatar
Coiler
Posts: 114
Joined: 29 Nov 2020, 09:06

Re: How to interupt KeyWait?

Post by Coiler » 08 Apr 2021, 14:03

You can set a global variable to 1 when F11 goes down (before KeyWait(), then set that variable to 0 when escape is pressed. Then just check the variable before taking action in your F11 hotkey. Or you can use KeyWait with a timer limit in a loop, and keep checking for Escape every so many milliseconds.

If it works for you, lexikos key-up is better than using KeyWait(), loops, or variables. I'm personally accustomed to supporting joystick buttons in my scripts, so I can never rely on key up :(
Post Reply

Return to “Ask for Help (v2)”