Disables or enables the user's ability to interact with the computer via keyboard, mouse, and perhaps other input devices.
BlockInput, Mode |
Parameters
Mode | One of the following words: On: The user is prevented from interacting with the computer (mouse and keyboard input has no effect). Off: Input is re-enabled.
The following additional modes are available on Windows XP/2000/NT4 or later. These modes operate independently of the above two modes. In other words, "BlockInput On" will continue to block input until "BlockInput Off" is used, even if one of the below modes is also in effect. Send: Input blocking is automatically enabled prior to each use of Send or SendRaw. This prevents any keystrokes physically typed by the user from disrupting the flow of simulated keystrokes. Input blocking is automatically turned back off after the command completes unless it was on beforehand. Mouse: Input blocking is automatically enabled prior to each use of MouseMove, MouseClick, or MouseClickDrag. This prevents any physical mouse activity by the user from disrupting the simulated mouse events. Input blocking is automatically turned back off after the command completes unless it was explicitly "on" beforehand. 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. This is also true for "BlockInput Send|Mouse|SendAndMouse". |
Remarks
When BlockInput is in effect, both the mouse and keyboard are disabled. This is a limitation of the system feature used to implement this command.
Input blocking is automatically and momentarily disabled whenever an ALT event is sent (then re-enabled afterward).
The table below shows how BlockInput behavior varies depending on 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 95 | No effect. |
Windows 98/Me | User input is blocked and AutoHotkey is unable to simulate input. |
Windows NT 4 (without ServicePack 6) | No effect. |
Windows NT 4 (with ServicePack 6) | User input is blocked but AutoHotkey can simulate most input. |
Windows 2000/XP | User input is blocked but AutoHotkey can simulate most input. |
If BlockInput becomes active while you're 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 On ; ... send keystrokes and mouse clicks ... ; BlockInput Off return
Note that commands such as WinMove will still work on Windows 98/Me when BlockInput is enabled. ControlSend might also work.
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
Send, MouseMove, MouseClick, MouseClickDrag
Example
if A_OSType <> WIN32_WINDOWS ; i.e. it's not Windows 9x. BlockInput, on Run, notepad WinWaitActive, Untitled - Notepad Send, {F5} ; pastes time and date BlockInput, off