Class GlobalHookBase
Represents an abstract implementation of IGlobalHook which raises events only when there is at least one subscriber.
Inherited Members
Namespace: SharpHook
Assembly: SharpHook.dll
Syntax
public abstract class GlobalHookBase : IGlobalHook, IDisposable
Constructors
| Improve this Doc View SourceGlobalHookBase()
Initializes a new instance of GlobalHookBase.
Declaration
protected GlobalHookBase()
GlobalHookBase(Boolean)
Initializes a new instance of GlobalHookBase.
Declaration
protected GlobalHookBase(bool runAsyncOnBackgroundThread)
Parameters
Type | Name | Description |
---|---|---|
Boolean | runAsyncOnBackgroundThread | true if RunAsync() should run the hook on a background thread. Otherwise, false. |
Properties
| Improve this Doc View SourceIsDisposed
Gets the value which indicates whether the global hook is disposed.
Declaration
public bool IsDisposed { get; }
Property Value
Type | Description |
---|---|
Boolean | true if the global hook is disposed. Otherwise, false. |
Remarks
A disposed global hook cannot be started again.
IsRunning
Gets the value which indicates whether the global hook is running.
Declaration
public bool IsRunning { get; }
Property Value
Type | Description |
---|---|
Boolean | true if the global hook is running. Otherwise, false. |
Methods
| Improve this Doc View SourceDispatchEvent(ref UioHookEvent)
Dispatches an event from libuiohook, i.e. raises the appropriate event.
Declaration
protected void DispatchEvent(ref UioHookEvent e)
Parameters
Type | Name | Description |
---|---|---|
UioHookEvent | e | The event to dispatch. |
Dispose()
Destroys the global hook.
Declaration
public void Dispose()
Remarks
After calling this method, the hook cannot be started again. If you want to do that, create a new instance of IGlobalHook.
Exceptions
Type | Condition |
---|---|
HookException | Stopping the hook has failed. |
Dispose(Boolean)
Destoys the global hook.
Declaration
protected virtual void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
Boolean | disposing | true if the method is called from the Dispose() method. Otherwise, false. |
Exceptions
Type | Condition |
---|---|
HookException | Stopping the hook has failed. |
Finalize()
Destroys the global hook if it's running.
Declaration
protected void Finalize()
HandleHookEvent(ref UioHookEvent)
When implemented in a derived class, represents a strategy for handling a hook event.
Declaration
protected abstract void HandleHookEvent(ref UioHookEvent e)
Parameters
Type | Name | Description |
---|---|---|
UioHookEvent | e | The event to handle. |
Remarks
Derived classes should call DispatchEvent(ref UioHookEvent) inside this method to raise the appropriate event.
OnHookDisabled(HookEventArgs)
Raises the HookDisabled event with this object as the sender.
Declaration
protected virtual void OnHookDisabled(HookEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
HookEventArgs | args | The arguments of the event. |
OnHookEnabled(HookEventArgs)
Raises the HookEnabled event with this object as the sender.
Declaration
protected virtual void OnHookEnabled(HookEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
HookEventArgs | args | The arguments of the event. |
OnKeyPressed(KeyboardHookEventArgs)
Raises the KeyPressed event with this object as the sender.
Declaration
protected virtual void OnKeyPressed(KeyboardHookEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
KeyboardHookEventArgs | args | The arguments of the event. |
OnKeyReleased(KeyboardHookEventArgs)
Raises the KeyReleased event with this object as the sender.
Declaration
protected virtual void OnKeyReleased(KeyboardHookEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
KeyboardHookEventArgs | args | The arguments of the event. |
OnKeyTyped(KeyboardHookEventArgs)
Raises the KeyTyped event with this object as the sender.
Declaration
protected virtual void OnKeyTyped(KeyboardHookEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
KeyboardHookEventArgs | args | The arguments of the event. |
OnMouseClicked(MouseHookEventArgs)
Raises the MouseClicked event with this object as the sender.
Declaration
protected virtual void OnMouseClicked(MouseHookEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
MouseHookEventArgs | args | The arguments of the event. |
OnMouseDragged(MouseHookEventArgs)
Raises the MouseDragged event with this object as the sender.
Declaration
protected virtual void OnMouseDragged(MouseHookEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
MouseHookEventArgs | args | The arguments of the event. |
OnMouseMoved(MouseHookEventArgs)
Raises the MouseMoved event with this object as the sender.
Declaration
protected virtual void OnMouseMoved(MouseHookEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
MouseHookEventArgs | args | The arguments of the event. |
OnMousePressed(MouseHookEventArgs)
Raises the MousePressed event with this object as the sender.
Declaration
protected virtual void OnMousePressed(MouseHookEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
MouseHookEventArgs | args | The arguments of the event. |
OnMouseReleased(MouseHookEventArgs)
Raises the MouseReleased event with this object as the sender.
Declaration
protected virtual void OnMouseReleased(MouseHookEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
MouseHookEventArgs | args | The arguments of the event. |
OnMouseWheel(MouseWheelHookEventArgs)
Raises the MouseWheel event with this object as the sender.
Declaration
protected virtual void OnMouseWheel(MouseWheelHookEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
MouseWheelHookEventArgs | args | The arguments of the event. |
Run()
Runs the global hook on the current thread, blocking it. The hook can be destroyed by calling the Dispose() method.
Declaration
public void Run()
Exceptions
Type | Condition |
---|---|
HookException | Starting the global hook has failed. |
InvalidOperationException | The global hook is already running. |
ObjectDisposedException | The global hook has been disposed. |
RunAsync()
Runs the global hook without blocking the current thread. The hook can be destroyed by calling the Dispose() method.
Declaration
public Task RunAsync()
Returns
Type | Description |
---|---|
Task | A Task which finishes when the hook is destroyed. |
Remarks
The hook is started on a separate thread.
Exceptions
Type | Condition |
---|---|
HookException | Starting the global hook has failed. |
InvalidOperationException | The global hook is already running. |
ObjectDisposedException | The global hook has been disposed. |
ThrowIfDisposed(String)
Throws an ObjectDisposedException if this object is disposed.
Declaration
protected void ThrowIfDisposed(string method = null)
Parameters
Type | Name | Description |
---|---|---|
String | method | The method which calls this method. |
Events
| Improve this Doc View SourceHookDisabled
An event which is raised when the global hook is disabled.
Declaration
public event EventHandler<HookEventArgs> HookDisabled
Event Type
Type | Description |
---|---|
EventHandler<HookEventArgs> |
Remarks
This event is raised when the Dispose() method is called.
HookEnabled
An event which is raised when the global hook is enabled.
Declaration
public event EventHandler<HookEventArgs> HookEnabled
Event Type
Type | Description |
---|---|
EventHandler<HookEventArgs> |
Remarks
This event is raised when the Run() or RunAsync() method is called.
KeyPressed
An event which is raised when a key is pressed.
Declaration
public event EventHandler<KeyboardHookEventArgs> KeyPressed
Event Type
Type | Description |
---|---|
EventHandler<KeyboardHookEventArgs> |
KeyReleased
An event which is raised when a key is released.
Declaration
public event EventHandler<KeyboardHookEventArgs> KeyReleased
Event Type
Type | Description |
---|---|
EventHandler<KeyboardHookEventArgs> |
KeyTyped
An event which is raised when a key is typed.
Declaration
public event EventHandler<KeyboardHookEventArgs> KeyTyped
Event Type
Type | Description |
---|---|
EventHandler<KeyboardHookEventArgs> |
MouseClicked
An event which is raised when a mouse button is clicked.
Declaration
public event EventHandler<MouseHookEventArgs> MouseClicked
Event Type
Type | Description |
---|---|
EventHandler<MouseHookEventArgs> |
MouseDragged
An event which is raised when the mouse cursor is dragged.
Declaration
public event EventHandler<MouseHookEventArgs> MouseDragged
Event Type
Type | Description |
---|---|
EventHandler<MouseHookEventArgs> |
MouseMoved
An event which is raised when the mouse cursor is moved.
Declaration
public event EventHandler<MouseHookEventArgs> MouseMoved
Event Type
Type | Description |
---|---|
EventHandler<MouseHookEventArgs> |
MousePressed
An event which is raised when a mouse button is pressed.
Declaration
public event EventHandler<MouseHookEventArgs> MousePressed
Event Type
Type | Description |
---|---|
EventHandler<MouseHookEventArgs> |
MouseReleased
An event which is raised when a mouse button is released.
Declaration
public event EventHandler<MouseHookEventArgs> MouseReleased
Event Type
Type | Description |
---|---|
EventHandler<MouseHookEventArgs> |
MouseWheel
An event which is raised when the mouse wheel is turned.
Declaration
public event EventHandler<MouseWheelHookEventArgs> MouseWheel
Event Type
Type | Description |
---|---|
EventHandler<MouseWheelHookEventArgs> |