Reputation: 23
As the title says, I've had trouble finding a way for my script to only block keyboard inputs during my script. Is there a method that I've overlooked to do this? Here's my code for reference:
toggle = 0
*xbutton1::
{
if GetKeyState("d", "P")
{
if GetKeyState("w", "P")
{
BlockInput On ;enabled
Send, {d up}
Send, {w up}
Send, {a down}
Send, {s down}
Send, {K}
BlockInput Off ;disabled when completed with the above actions ^ so no key inputs interfere
Sleep, -1
Send, {a up}
Send, {s up}
Send, {d down}
Send, {w down}
return
}
Thanks! I'd appreciate any info or tips.
Upvotes: 1
Views: 3040
Reputation: 21
There is a modified AHKV2 version of it, thanks to the accepted answer:
func_BlockKeyboard(state){
Loop 512
{
Key := Format("SC{:X}",A_Index)
If (state = "On")
Hotkey Key, do_nothing, "On UseErrorLevel"
else
Hotkey Key, do_nothing, "Off UseErrorLevel"
}
KeyboardKey:
return
}
do_nothing(ThisHotkey)
{
return
}
Insert::func_BlockKeyboard("On")
Insert & End::func_BlockKeyboard("Off")
Upvotes: 2
Reputation: 10568
You can create a function to only block keyboard input:
; Press F1 to block keyboard input for 10 seconds:
$F1::
BlockKeyboard("On")
Sleep, 10000
BlockKeyboard("Off")
return
BlockKeyboard(state){
Loop, 512
{
Key := Format("SC{:X}",A_Index)
If (state = "On")
Hotkey, *%Key%, KeyboardKey, On UseErrorLevel
else
Hotkey, *%Key%, KeyboardKey, Off UseErrorLevel
}
KeyboardKey:
return
}
Upvotes: 2