Context Sensitive Keyboard Control: AutoHotkey

email me

Using AutoHotkey, you can block specific keys on the keyboard:

SetTitleMatchMode, 2
SendMode Input 
#NoEnv

Keys := ["F1","F2","F3","F4","F5","F6","F7","F8","F9","F10","F11","F12","Backspace","LButton","RButton","Escape","Tab","Delete","Numpad0","Numpad1","Numpad2","Numpad3","Numpad4","Numpad5","Numpad6","Numpad7","Numpad8","Numpad9","NumpadDot","NumpadDiv","NumpadMult","NumpadAdd","NumpadSub","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","1","2","3","4","5","6","7","8","9","0",";","'",",",".","/","\","[","]","-","=","{","}","+","_","!","@","#","$","%","^","&","*","(",")","<",">","?","``","~","|"]

for k, v in Keys
  In(v, "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z") ? (HotKey("+" v, "BlockKey"),  HotKey("^" v, "BlockKey"), HotKey(v, "BlockKey")) : (HotKey(v, "BlockKey"), HotKey("^" v, "BlockKey")) ?  (HotKey("+" v, "BlockKey"),  HotKey("!" v, "BlockKey"), HotKey(v, "BlockKey")) : (HotKey(v, "BlockKey"), HotKey("!" v, "BlockKey"))
return

#If (WinActive("ahk_class Notepad"))

BlockKey:
Key := InStr(A_ThisHotkey, "+", "false", "1") || InStr(A_ThisHotkey, "^", "false", "1") || InStr(A_ThisHotkey, "!", "false", "1")  ? (SubStr(A_ThisHotkey, "0", "1"), Mod := SubStr(A_ThisHotkey, "1", "1"))  : (A_ThisHotkey, Mod := "") ; || InStr(A_ThisHotkey, "!", "false", "1") 
If (WinActive("ahk_class Notepad") && Mod . Key <> "^c")
   return
else
   Send, %Mod%{%Key%}
return

In(var, Matchlist)
{
   if var in %Matchlist%
      return True
}

Hotkey(ByRef KeyName, ByRef Label) 
{
   HotKey, %KeyName%, %Label%
}

 

 

Notes

Ahk2Exe can be used in the following ways:

 

  1. GUI Interface: Run the “Convert .ahk to .exe” item in the Start Menu.
  2. Right-click: Within an open Explorer window, you can right-click any .ahk file and select “Compile Script” (only available if the script compiler option was chosen when AutoHotkey was installed).

Download AutoHotkey