How do I disable certain keys using a key in AutoHotkey?

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?


Solution 1:

AutoHotkey has 2 functions that might help you:

  1. "Suspend", which will stop all hotkeys in a script from working.
  2. "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.