abort keyhook Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
nascent
Posts: 9
Joined: 01 Mar 2017, 09:10

abort keyhook

16 Apr 2021, 07:43

Hi,

I know how to hook a key eg:

*n::
Run Notepad
return


but how would i abandon the key intercept?

example: I have a variable interceptNKey

interceptNKey := false
n::
if (interceptNKey = true) {
Run Notepad
return
}


if the interceptNKey is true the keypress successfully opens notepad, but if it's false the n is absorbed, whereas I would want n to function normally.
The only workaround I've found for now is to send n in an else statement like:
interceptNKey := false
n::
if (interceptNKey = true) {
Run Notepad
return
}
else {
send n
}


However this is not a real solution. Plus it doesn't work as the sent n is absorbed by the function and you end up in an infinite loop of n being pressed and absorbed by the hook then pressing n which is absorbed.

Surely there's just a way to break hook and allow the n key to continue to get through?
Rohwedder
Posts: 7623
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: abort keyhook  Topic is solved

16 Apr 2021, 08:13

Hallo,
try:

Code: Select all

interceptNKey := false

#If interceptNKey ; means: If (interceptNKey = true)
n::Run Notepad
#If
User avatar
nascent
Posts: 9
Joined: 01 Mar 2017, 09:10

Re: abort keyhook

16 Apr 2021, 10:52

Rohwedder wrote:
16 Apr 2021, 08:13
Hallo,
try:

Code: Select all

interceptNKey := false

#If interceptNKey ; means: If (interceptNKey = true)
n::Run Notepad
#If
You're a genius. That indeed seems to work well.
I didn't know about #if

many thanks

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: rc76 and 204 guests