Class MouseHook
Provides a mechanism for hooking all mouse events within the operating system.
public static class MouseHook
- Inheritance
-
MouseHook
- Inherited Members
Properties
IsInstalled
Indicates whether MouseHook has been installed and is capturing mouse events.
public static bool IsInstalled { get; }
Property Value
Methods
Install()
Installs the mouse hook, capturing all global mouse events.
public static void Install()
Remarks
This hook is called in the context of the thread that installed it. The call is made by sending a message to the thread that installed the hook. Therefore, the thread that installed the hook must have a message loop.
The hook procedure should process a message in less time than the data entry specified in the LowLevelHooksTimeout
value in the following registry key:
HKEY_CURRENT_USER\Control Panel\Desktop
The value is in milliseconds. If the hook procedure times out, the system passes the message to the next hook. However, on Windows 7 and later, the hook is silently removed without being called. There is no way for the application to know whether the hook is removed.
Windows 10 version 1709 and later The maximum timeout value the system allows is 1000 milliseconds (1 second). The system will default to using a 1000 millisecond timeout if the LowLevelHooksTimeout
value is set to a value larger than 1000.
Exceptions
- Win32Exception
The hook could not be installed.
TryInstall()
Attempts to install the mouse hook.
public static bool TryInstall()
Returns
TryUninstall()
Attempts to uninstall the mouse hook.
public static bool TryUninstall()
Returns
Uninstall()
Uninstalls the mouse hook, and stops further mouse events from being captured.
public static void Uninstall()
Exceptions
- Win32Exception
The hook could not be uninstalled.
Events
MouseClick
Occurs when a mouse button is clicked.
public static event MouseEventHandler? MouseClick
Event Type
Remarks
Event handlers should aim to be as fast as possible, otherwise mouse performance may be impacted, or the hook removed by the operating system. See Install() for more information.
MouseDoubleClick
Occurs when a mouse button is double clicked.
public static event MouseEventHandler? MouseDoubleClick
Event Type
Remarks
Event handlers should aim to be as fast as possible, otherwise mouse performance may be impacted, or the hook removed by the operating system. See Install() for more information.
MouseDown
Occurs when a mouse button is pressed.
public static event MouseEventHandler? MouseDown
Event Type
Remarks
Event handlers should aim to be as fast as possible, otherwise mouse performance may be impacted, or the hook removed by the operating system. See Install() for more information.
MouseMove
Occurs when the mouse pointer is moved.
public static event MouseEventHandler? MouseMove
Event Type
Remarks
Event handlers should aim to be as fast as possible, otherwise mouse performance may be impacted, or the hook removed by the operating system. See Install() for more information.
MouseUp
Occurs a mouse button is released.
public static event MouseEventHandler? MouseUp
Event Type
Remarks
Event handlers should aim to be as fast as possible, otherwise mouse performance may be impacted, or the hook removed by the operating system. See Install() for more information.
MouseWheel
Occurs when the mouse wheel moves.
public static event MouseEventHandler? MouseWheel
Event Type
Remarks
Event handlers should aim to be as fast as possible, otherwise mouse performance may be impacted, or the hook removed by the operating system. See Install() for more information.