JSI Tip 9554. How can I disable mouse and keyboard input for n seconds?

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 off
if \{%1\}==\{\} goto err
if 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"
set sec=%1
set sec=%sec:"=%
if "%sec:~0,1%" EQU "0" goto finish
if 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%
goto :EOF
call :Quiet>nul 2>&1
goto :EOF
close "BlockInput_%UserName%_%ComputerName%*"
goto :EOF
@echo Syntax: BlockInput Seconds

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.