How do I disable certain keys using a key in AutoHotkey?
AutoHotkey has 2 functions that might help you:
- "Suspend", which will stop all hotkeys in a script from working.
- "return", which can be used to disable single keys or hotkeys (and mouse buttons).
Now you can turn these 2 functions to your advantage.
Just place this line of code somewhere in your script:
end::Suspend
This will suspend the script when you press End. Once the script is suspended, the keys will function normally. Once you activate the script with End, the keys will be disabled.
You can disable keys by running a script like this:
a::return
b::return
...
Works like a charm.
Just for simplicity's sake, the whole script will look like this:
end::Suspend
a::return
b::return
Just add any keys you want to disable below the last return. If you want to disable other keys than letters or numbers, just consult the comprehensive Key List. Place the name of the key before the 2 colons: e.g. NumPad0::return
Save the script in a file with extension .ahk, like "disablekeys.ahk". Double click on it or create a shortcut to it in the startup folder if you want it to start automatically. Done.
Related videos on Youtube
Admin
Updated on September 18, 2022Comments
-
Admin over 1 year
I want the "End" key to block/lock certain keys like a,s,d,i,j,k,l. And when I click "End" again to unblock the same keys (a,s,d,i,j,k,l). How can I do this in Autohotkey? Can someone please tell me the commands and functions?
-
user598527 over 7 yearsYou don't have to use
return
,[key]::
is enough. -
user 99572 is fine over 7 years@user598527 You're right.
-
Janac Meena about 5 yearsAny idea how I can make this work in a particular application? superuser.com/questions/1427953/…
-
user 99572 is fine about 5 years@JanacMeena I see you got the answer. TitleMatch is a bit cumbersome to get right.