Call it as BlockKeyboard(true)
See password within code, press those keys in order to unlock.
BlockKeyboard(block=-1) ; -1, true or false.
{ ;Thanks to Lexikos
static hHook = 0, cb = 0
if !cb ; register callback once only.
cb := RegisterCallback("BlockKeyboardProc","Fast")
if (block = -1) ; toggle
block := (hHook=0)
if ( (hHook!=0) = (block!=0) ) ; already (un)blocked, no action necessary.
return
if (block)
{
hHook := DllCall("SetWindowsHookEx"
, "int", 13 ; WH_KEYBOARD_LL
, "uint", cb ; lpfn (callback)
, "uint", 0 ; hMod (NULL)
, "uint", 0) ; dwThreadId (all threads)
}
else
{
DllCall("UnhookWindowsHookEx", "uint", hHook)
hHook = 0
}
}
BlockKeyboardProc(nCode, wParam, lParam)
{
static count=1, Keys:=["r","F12","LCtrl",".","CapsLock"] ;password, some keys don't work, beware!
if (NumGet(lParam+8) & 0x80)
{
if (NumGet(lParam+4)=GetKeyHex(Keys[count]))
count++
else
count=1
If (count=Keys.MaxIndex()+1)
BlockKeyboard(false)
}
return 1
}
GetKeyHex(Key)
{
OldFormat:=A_FormatInteger
SetFormat, Integer, H
Ans:=GetKeySC(Key) + 0
SetFormat, Integer, % OldFormat
return Ans
}