Function Reference


BlockInput

Disable/enable the mouse and keyboard.

BlockInput ( flag )

Parameters

flag     $BI_DISABLE (1) = Disable user input
    $BI_ENABLE (0) = Enable user input

Constants are defined in "AutoItConstants.au3".

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.
Windows Vista and above User input is blocked and AutoIt can simulate mouse and keyboard if #RequireAdmin is used.

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

Related

Send

Example

#RequireAdmin

#include <AutoItConstants.au3>

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($BI_DISABLE)

        ; 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($BI_ENABLE)

        ; 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