PageRenderTime 28ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/AutoHotkey.docset/Contents/Resources/Documents/commands/BlockInput.htm

https://gitlab.com/ahkscript/Autohotkey.docset
HTML | 60 lines | 53 code | 7 blank | 0 comment | 0 complexity | 3a527463a5c2934a6fdab865b7e61015 MD5 | raw file
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <title>BlockInput</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  6. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  7. <link href="../static/theme.css" rel="stylesheet" type="text/css" />
  8. <script src="../static/content.js" type="text/javascript"></script>
  9. </head>
  10. <body>
  11. <h1>BlockInput</h1>
  12. <p>Disables or enables the user's ability to interact with the computer via keyboard and mouse.</p>
  13. <pre class="Syntax">BlockInput, Mode</pre>
  14. <h3>Parameters</h3>
  15. <dl>
  16. <dt>Mode</dt>
  17. <dd><p><strong><u>Mode 1</u></strong>: One of the following words:</p>
  18. <p><strong>On</strong>: The user is prevented from interacting with the computer (mouse and keyboard input has no effect).</p>
  19. <p><strong>Off</strong>: Input is re-enabled.</p>
  20. <p><strong><u>Mode 2</u></strong>: This mode operates independently of the other two. For example, <code>BlockInput On</code> will continue to block input until <code>BlockInput Off</code> is used, even if one of the below is also in effect.</p>
  21. <p><strong>Send</strong>: The user's keyboard and mouse input is ignored while a <a href="Send.htm">Send</a> or <a href="Send.htm">SendRaw</a> is in progress (the traditional <a href="SendMode.htm">SendEvent mode</a> only). 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 <code>BlockInput On</code>).</p>
  22. <p><strong>Mouse</strong>: The user's keyboard and mouse input is ignored while a <a href="Click.htm">Click</a>, <a href="MouseMove.htm">MouseMove</a>, <a href="MouseClick.htm">MouseClick</a>, or <a href="MouseClickDrag.htm">MouseClickDrag</a> is in progress (the traditional <a href="SendMode.htm">SendEvent mode</a> only). This prevents the user's mouse movements and clicks from disrupting the simulated mouse events. When the mouse command finishes, input is re-enabled (unless still blocked by a previous use of <code>BlockInput On</code>).</p>
  23. <p><strong>SendAndMouse</strong>: A combination of the above two modes.</p>
  24. <p><strong>Default</strong>: Turns off both the <em>Send</em> and the <em>Mouse</em> modes, but does not change the current state of input blocking. For example, if <code>BlockInput On</code> is currently in effect, using <code>BlockInput Default</code> will not turn it off.</p>
  25. <p id="MouseMove"><u><strong>Mode 3</strong> (requires v1.0.43.11+)</u>: This mode operates independently of the other two. For example, if <code>BlockInput On</code> and <code>BlockInput MouseMove</code> are both in effect, mouse movement will be blocked until both are turned off.</p>
  26. <p><strong>MouseMove</strong>: 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 command, the <a href="_InstallMouseHook.htm">mouse hook</a> is installed (if it is not already). In addition, the script becomes <a href="_Persistent.htm">persistent</a>, meaning that <a href="ExitApp.htm">ExitApp</a> should be used to terminate it. The mouse hook will stay installed until the next use of the <a href="Suspend.htm">Suspend</a> or <a href="Hotkey.htm">Hotkey</a> command, at which time it is removed if not required by any hotkeys or hotstrings (see <a href="_Hotstring.htm">#Hotstring NoMouse</a>).</p>
  27. <p><strong>MouseMoveOff</strong>: Allows the user to move the mouse cursor.</p></dd>
  28. </dl>
  29. <h3>Remarks</h3>
  30. <p><strong>Note:</strong> <code>BlockInput On</code> might have no effect if UAC is enabled and the script has not been run as administrator. For more information, refer to the <a href="../FAQ.htm#uac">FAQ</a>.</p>
  31. <p>In preference to BlockInput, it is often better to use <code><a href="SendMode.htm">SendMode Input</a></code> or <code><a href="SendMode.htm">SendMode Play</a></code> 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.</p>
  32. <p>If BlockInput becomes active while the user is holding down keys, it might cause those keys to become &quot;stuck down&quot;. This can be avoided by waiting for the keys to be released prior to turning BlockInput on, as in this example:</p>
  33. <pre>^!p::
  34. KeyWait Control <em>; Wait for the key to be released. Use one KeyWait for each of the hotkey's modifiers.</em>
  35. KeyWait Alt
  36. BlockInput On
  37. <em>; ... send keystrokes and mouse clicks ...</em>
  38. BlockInput Off
  39. return</pre>
  40. <p>Input blocking is automatically and momentarily disabled whenever an ALT event is sent (then re-enabled afterward).</p>
  41. <p>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.</p>
  42. <p>Certain types of <a href="_UseHook.htm">hook hotkeys</a> can still be triggered when BlockInput is on. Examples include <code>MButton</code> (mouse hook) and <code>LWin &amp; Space</code> (keyboard hook with explicit prefix rather than modifiers <code>$#</code>).</p>
  43. <p>Input is automatically re-enabled when the script closes.</p>
  44. <h3>Related</h3>
  45. <p><a href="SendMode.htm">SendMode</a>, <a href="Send.htm">Send</a>, <a href="Click.htm">Click</a>, <a href="MouseMove.htm">MouseMove</a>, <a href="MouseClick.htm">MouseClick</a>, <a href="MouseClickDrag.htm">MouseClickDrag</a></p>
  46. <h3>Example</h3>
  47. <pre class="NoIndent">BlockInput, on
  48. Run, notepad
  49. WinWaitActive, Untitled - Notepad
  50. Send, {F5} <em>; pastes time and date</em>
  51. BlockInput, off</pre>
  52. </body>
  53. </html>