Click to Rate and Give Feedback
MSDN
MSDN Library
User Interface
User Input
Keyboard Input
Functions
 BlockInput Function

  Switch on low bandwidth view
BlockInput Function

The BlockInput function blocks keyboard and mouse input events from reaching applications.

Syntax

BOOL BlockInput(      
    BOOL fBlockIt );

Parameters

fBlockIt
[in] Specifies the function's purpose. If this parameter is TRUE, keyboard and mouse input events are blocked. If this parameter is FALSE, keyboard and mouse events are unblocked. Note that only the thread that blocked input can successfully unblock input.

Return Value

If the function succeeds, the return value is nonzero.

If input is already blocked, the return value is zero. To get extended error information, call GetLastError.

Remarks

When input is blocked, real physical input from the mouse or keyboard will not affect the input queue's synchronous key state (reported by GetKeyState and GetKeyboardState), nor will it affect the asynchronous key state (reported by GetAsyncKeyState). However, the thread that is blocking input can affect both of these key states by calling SendInput. No other thread can do this.

The system will unblock input in the following cases:

  • The thread that blocked input unexpectedly exits without calling BlockInput with fBlock set to FALSE. In this case, the system cleans up properly and re-enables input.
  • Windows 95/98/Me: The system displays the Close Program/Fault dialog box. This can occur if the thread faults or if the user presses CTRL+ALT+DEL.
  • Windows 2000/XP: The user presses CTRL+ALT+DEL or the system invokes the Hard System Error modal message box (for example, when a program faults or a device fails).

Function Information

Minimum DLL Versionuser32.dll
HeaderDeclared in winable.h
Import libraryUser32.lib
Minimum operating systems Windows 98, Windows 2000

See Also

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Vista requires elevation for this function to work      byteboon   |   Edit   |   Show History
On Vista, this function must be executed from an elevated process. Also on Vista, when input is blocked the LLKHF_INJECTED flag is not set in the hook's KBDLLHOOKSTRUCT for the keys you inject.
vb.net syntax      dmex   |   Edit   |   Show History
<DllImport("user32.dll", CharSet:=CharSet.Auto, ExactSpelling:=True)> _
Public Shared Function BlockInput(<[In], MarshalAs(UnmanagedType.Bool)> ByVal fBlockIt As Boolean) As <MarshalAs(UnmanagedType.Bool)> Boolean End Function
Flag as ContentBug
C# syntax      dmex   |   Edit   |   Show History
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]
public static extern bool BlockInput([In, MarshalAs(UnmanagedType.Bool)] bool fBlockIt);
Tags What's this?: c# (x) syntax (x) Add a tag
Flag as ContentBug
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker