Function Reference


BlockInput

Disable/enable the mouse and keyboard.

BlockInput ( flag )

Parameters

flag 1 = Disable user input
0 = Enable user input

Return Value

Success: 1.
Failure: 0. Already Enable or #RequireAdmin not used.

Remarks

The table below shows how BlockInput() behavior depends on the Windows version; however, pressing Ctrl+Alt+Del on any platform will re-enable input due to a Windows API feature.

Operating System "BlockInput()" Results
Windows XP User input is blocked and AutoIt can simulate mouse and keyboard input. See remarks below for an issue with Windows XP SP1.
Windows Vista and above User input is blocked and AutoIt can simulate mouse and keyboard if #RequireAdmin is used.

A Windows hotfix was released for Windows XP SP1 that contained a bug that prevents the Alt keystroke from being sent (via the Send() function) while BlockInput() is active. The Windows bug is fixed in Windows XP SP2 and newer.

BlockInput() only affects user-input. Input from functions like Send() or MouseMove() still work.

Related

Send()

Example

Example()

Func Example()
    ; Run Notepad
    Run("notepad.exe")

    ; Wait 10 seconds for the Notepad window to appear.
    Local $hWnd = WinWait("[CLASS:Notepad]", "", 10)

    ; Disable user input from the mouse and keyboard.
    BlockInput(1)

    ; Wait for 2 seconds.
    Sleep(2000)

    ; Send the 'F5' key to the edit control of Notepad to display the date and time. The handle returned by WinWait is used for the "title" parameter of ControlSend.
    ControlSend($hWnd, "", "Edit1", "{F5}")

    ; Enable user input from the mouse and keyboard.
    BlockInput(0)

    ; Wait for 2 seconds.
    Sleep(2000)

    ; Close the Notepad window using the handle returned by WinWait.
    WinClose($hWnd)

    ; Now a screen will pop up and ask to save the changes, the classname of the window is called
    ; "#32770" and simulating the "TAB" key to move to the second button in which the "ENTER" is simulated to not "save the file"
    WinWaitActive("[CLASS:#32770]")
    Sleep(500)
    Send("{TAB}{ENTER}")
EndFunc   ;==>Example