JSI Tip 9554. How can I disable mouse and keyboard input for n seconds?
Jerold Schulman
July 12, 2005
1 Min Read
In tip 6864, I introduced AutoIt freeware.
Using the AutoItX functionality, included with a Complete install, I have scripted BlockInput.bat to disable mouse and keyboard input for the number of seconds you specify.
The syntax for using BlockInput.bat is:
call BlockInput Seconds
NOTE: If Seconds starts with, or is, 0, any active block is terminated, restoring keyboard and mouse input.
NOTE: During the period that input is blocked, your script, and all other processes, will continue to process.
NOTE: BlockInput.bat uses Close.exe, which should be located in a folder that is in your PATH.
BlockInput.bat contains:
@echo offsetlocalif {%1}=={} goto errif exist "%TEMP%BlockInput.vbs" goto :block@echo set objArgs = WScript.Arguments>"%TEMP%BlockInput.vbs"@echo Set oAutoIt = CreateObject("AutoItX.Control")>>"%TEMP%BlockInput.vbs"@echo oAutoIt.BlockInput "On">>"%TEMP%BlockInput.vbs"@echo WScript.Sleep objArgs(0)>>"%TEMP%BlockInput.vbs":blockset sec=%1set sec=%sec:"=%if "%sec:~0,1%" EQU "0" goto finishif exist "%TEMP%BlockInput_%UserName%_%ComputerName%_*.CMD" del /q "%TEMP%BlockInput_%UserName%_%ComputerName%_*.CMD" set wrk="%TEMP%BlockInput_%UserName%_%ComputerName%_%RANDOM%.CMD"@echo @echo off>%wrk%@echo cscript //nologo "%TEMP%BlockInput.vbs" %sec%000>>%wrk%@echo exit>>%wrk%start /min "BlockInput_%UserName%_%ComputerName%" %wrk%endlocalgoto :EOF:finishcall :Quiet>nul 2>&1endlocalgoto :EOF:Quietclose "BlockInput_%UserName%_%ComputerName%*"goto :EOF:err@echo Syntax: BlockInput Secondsendlocal
About the Author
Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.
You May Also Like