BlockInput

Disables or enables the user's ability to interact with the computer via keyboard and mouse.

BlockInput OnOff
BlockInput SendMouse
BlockInput MouseMove

Parameters

OnOff

Type: String or Integer (boolean)

This mode blocks all user inputs unconditionally. Specify one of the following values:

On or 1 (true): The user is prevented from interacting with the computer (mouse and keyboard input has no effect).

Off or 0 (false): Input is re-enabled.

SendMouse

Type: String

This mode only blocks user inputs while specific send and/or mouse functions are in progress. Specify one of the following words:

Send: The user's keyboard and mouse input is ignored while a SendEvent is in progress (including Send and SendText if SendMode "Event" has been used). This prevents the user's keystrokes from disrupting the flow of simulated keystrokes. When the Send finishes, input is re-enabled (unless still blocked by a previous use of BlockInput "On").

Mouse: The user's keyboard and mouse input is ignored while a Click, MouseMove, MouseClick, or MouseClickDrag is in progress (the traditional SendEvent mode only). This prevents the user's mouse movements and clicks from disrupting the simulated mouse events. When the mouse action finishes, input is re-enabled (unless still blocked by a previous use of BlockInput "On").

SendAndMouse: A combination of the above two modes.

Default: Turns off both the Send and the Mouse modes, but does not change the current state of input blocking. For example, if BlockInput "On" is currently in effect, using BlockInput "Default" will not turn it off.

MouseMove

Type: String

This mode only blocks the mouse cursor movement. Specify one of the following words:

MouseMove: The mouse cursor will not move in response to the user's physical movement of the mouse (DirectInput applications are a possible exception). When a script first uses this function, the mouse hook is installed (if it is not already). The mouse hook will stay installed until the next use of the Suspend or Hotkey function, at which time it is removed if not required by any hotkeys or hotstrings (see #Hotstring NoMouse).

MouseMoveOff: Allows the user to move the mouse cursor.

Remarks

All three BlockInput modes (OnOff, SendMouse and MouseMove) operate independently of each other. For example, BlockInput "On" will continue to block input until BlockInput "Off" is used, even if one of the words from SendMouse is also in effect. Another example is, if BlockInput "On" and BlockInput "MouseMove" are both in effect, mouse movement will be blocked until both are turned off.

Note: The OnOff and SendMouse modes might have no effect if UAC is enabled or the script has not been run as administrator. For more information, refer to the FAQ.

In preference to BlockInput, it is often better to use SendMode "Input" or SendMode "Play" so that keystrokes and mouse clicks become uninterruptible. This is because unlike BlockInput, those modes do not discard what the user types during the send; instead, those keystrokes are buffered and sent afterward. Avoiding BlockInput also avoids the need to work around sticking keys as described in the next paragraph.

If BlockInput becomes active while the user is holding down keys, it might cause those keys to become "stuck down". This can be avoided by waiting for the keys to be released prior to turning BlockInput on, as in this example:

^!p::
{
    KeyWait "Control"  ; Wait for the key to be released.  Use one KeyWait for each of the hotkey's modifiers.
    KeyWait "Alt"
    BlockInput True
    ; ... send keystrokes and mouse clicks ...
    BlockInput False
}

Input blocking is automatically and momentarily disabled whenever an Alt event is sent (then re-enabled afterward).

When BlockInput is in effect, user input is blocked but AutoHotkey can simulate keystrokes and mouse clicks. However, pressing Ctrl+Alt+Del will re-enable input due to a Windows API feature.

Certain types of hook hotkeys can still be triggered when BlockInput is on. Examples include MButton (mouse hook) and LWin & Space (keyboard hook with explicit prefix rather than modifiers "$#").

Input is automatically re-enabled when the script closes.

Related

SendMode, Send, Click, MouseMove, MouseClick, MouseClickDrag

Examples

#1

BlockInput true
Run "notepad"
WinWaitActive "ahk_class Notepad"
Send "{F5}" ; pastes time and date
BlockInput false