Table of Contents

Class GlobalHookBase

Namespace
SharpHook
Assembly
SharpHook.dll

Represents an abstract implementation of IGlobalHook which defines everything needed except for a strategy for dispatching events and uses a global hook provider (libuiohook by default).

public abstract class GlobalHookBase : IGlobalHook, IDisposable
Inheritance
GlobalHookBase
Implements
Derived
Inherited Members

Constructors

GlobalHookBase()

Initializes a new instance of GlobalHookBase.

protected GlobalHookBase()
See Also

GlobalHookBase(IGlobalHookProvider)

Initializes a new instance of GlobalHookBase.

protected GlobalHookBase(IGlobalHookProvider globalHookProvider)

Parameters

globalHookProvider IGlobalHookProvider

The underlying global hook provider.

Exceptions

ArgumentNullException

globalHookProvider is null.

See Also

GlobalHookBase(IGlobalHookProvider, bool)

Initializes a new instance of GlobalHookBase.

protected GlobalHookBase(IGlobalHookProvider globalHookProvider, bool runAsyncOnBackgroundThread)

Parameters

globalHookProvider IGlobalHookProvider

The underlying global hook provider.

runAsyncOnBackgroundThread bool

true if RunAsync() should run the hook on a background thread. Otherwise, false.

Exceptions

ArgumentNullException

globalHookProvider is null.

See Also

GlobalHookBase(bool)

Initializes a new instance of GlobalHookBase.

protected GlobalHookBase(bool runAsyncOnBackgroundThread)

Parameters

runAsyncOnBackgroundThread bool

true if RunAsync() should run the hook on a background thread. Otherwise, false.

See Also

Properties

IsDisposed

Gets the value which indicates whether the global hook is disposed.

public bool IsDisposed { get; }

Property Value

bool

true if the global hook is disposed. Otherwise, false.

Remarks

A disposed global hook cannot be started again.

See Also

IsRunning

Gets the value which indicates whether the global hook is running.

public bool IsRunning { get; }

Property Value

bool

true if the global hook is running. Otherwise, false.

See Also

Methods

DispatchEvent(ref UioHookEvent)

Dispatches an event from libuiohook, i.e. raises the appropriate event.

protected void DispatchEvent(ref UioHookEvent e)

Parameters

e UioHookEvent

The event to dispatch.

See Also

Dispose()

Destroys the global hook.

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

HookException

Stopping the hook has failed.

See Also

Dispose(bool)

Destoys the global hook.

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

true if the method is called from the Dispose() method. Otherwise, false.

Exceptions

HookException

Stopping the hook has failed.

See Also

~GlobalHookBase()

Destroys the global hook if it's running.

protected ~GlobalHookBase()
See Also

HandleHookEvent(ref UioHookEvent)

When implemented in a derived class, represents a strategy for handling a hook event.

protected abstract void HandleHookEvent(ref UioHookEvent e)

Parameters

e UioHookEvent

The event to handle.

Remarks

Derived classes should call DispatchEvent(ref UioHookEvent) inside this method to raise the appropriate event.

See Also

OnHookDisabled(HookEventArgs)

Raises the HookDisabled event with this object as the sender.

protected virtual void OnHookDisabled(HookEventArgs args)

Parameters

args HookEventArgs

The arguments of the event.

See Also

OnHookEnabled(HookEventArgs)

Raises the HookEnabled event with this object as the sender.

protected virtual void OnHookEnabled(HookEventArgs args)

Parameters

args HookEventArgs

The arguments of the event.

See Also

OnKeyPressed(KeyboardHookEventArgs)

Raises the KeyPressed event with this object as the sender.

protected virtual void OnKeyPressed(KeyboardHookEventArgs args)

Parameters

args KeyboardHookEventArgs

The arguments of the event.

See Also

OnKeyReleased(KeyboardHookEventArgs)

Raises the KeyReleased event with this object as the sender.

protected virtual void OnKeyReleased(KeyboardHookEventArgs args)

Parameters

args KeyboardHookEventArgs

The arguments of the event.

See Also

OnKeyTyped(KeyboardHookEventArgs)

Raises the KeyTyped event with this object as the sender.

protected virtual void OnKeyTyped(KeyboardHookEventArgs args)

Parameters

args KeyboardHookEventArgs

The arguments of the event.

See Also

OnMouseClicked(MouseHookEventArgs)

Raises the MouseClicked event with this object as the sender.

protected virtual void OnMouseClicked(MouseHookEventArgs args)

Parameters

args MouseHookEventArgs

The arguments of the event.

See Also

OnMouseDragged(MouseHookEventArgs)

Raises the MouseDragged event with this object as the sender.

protected virtual void OnMouseDragged(MouseHookEventArgs args)

Parameters

args MouseHookEventArgs

The arguments of the event.

See Also

OnMouseMoved(MouseHookEventArgs)

Raises the MouseMoved event with this object as the sender.

protected virtual void OnMouseMoved(MouseHookEventArgs args)

Parameters

args MouseHookEventArgs

The arguments of the event.

See Also

OnMousePressed(MouseHookEventArgs)

Raises the MousePressed event with this object as the sender.

protected virtual void OnMousePressed(MouseHookEventArgs args)

Parameters

args MouseHookEventArgs

The arguments of the event.

See Also

OnMouseReleased(MouseHookEventArgs)

Raises the MouseReleased event with this object as the sender.

protected virtual void OnMouseReleased(MouseHookEventArgs args)

Parameters

args MouseHookEventArgs

The arguments of the event.

See Also

OnMouseWheel(MouseWheelHookEventArgs)

Raises the MouseWheel event with this object as the sender.

protected virtual void OnMouseWheel(MouseWheelHookEventArgs args)

Parameters

args MouseWheelHookEventArgs

The arguments of the event.

See Also

Run()

Runs the global hook on the current thread, blocking it. The hook can be destroyed by calling the Dispose() method.

public void Run()

Exceptions

HookException

Starting the global hook has failed.

InvalidOperationException

The global hook is already running.

ObjectDisposedException

The global hook has been disposed.

See Also

RunAsync()

Runs the global hook without blocking the current thread. The hook can be destroyed by calling the Dispose() method.

public Task RunAsync()

Returns

Task

A Task which finishes when the hook is destroyed.

Remarks

The hook is started on a separate thread.

Exceptions

HookException

Starting the global hook has failed.

InvalidOperationException

The global hook is already running.

ObjectDisposedException

The global hook has been disposed.

See Also

ThrowIfDisposed(string?)

Throws an ObjectDisposedException if this object is disposed.

protected void ThrowIfDisposed(string? method = null)

Parameters

method string

The method which calls this method.

See Also

Events

HookDisabled

An event which is raised when the global hook is disabled.

public event EventHandler<HookEventArgs>? HookDisabled

Event Type

EventHandler<HookEventArgs>

Remarks

This event is raised when the Dispose() method is called.

See Also

HookEnabled

An event which is raised when the global hook is enabled.

public event EventHandler<HookEventArgs>? HookEnabled

Event Type

EventHandler<HookEventArgs>

Remarks

This event is raised when the Run() or RunAsync() method is called.

See Also

KeyPressed

An event which is raised when a key is pressed.

public event EventHandler<KeyboardHookEventArgs>? KeyPressed

Event Type

EventHandler<KeyboardHookEventArgs>
See Also

KeyReleased

An event which is raised when a key is released.

public event EventHandler<KeyboardHookEventArgs>? KeyReleased

Event Type

EventHandler<KeyboardHookEventArgs>
See Also

KeyTyped

An event which is raised when a key is typed.

public event EventHandler<KeyboardHookEventArgs>? KeyTyped

Event Type

EventHandler<KeyboardHookEventArgs>
See Also

MouseClicked

An event which is raised when a mouse button is clicked.

public event EventHandler<MouseHookEventArgs>? MouseClicked

Event Type

EventHandler<MouseHookEventArgs>
See Also

MouseDragged

An event which is raised when the mouse cursor is dragged.

public event EventHandler<MouseHookEventArgs>? MouseDragged

Event Type

EventHandler<MouseHookEventArgs>
See Also

MouseMoved

An event which is raised when the mouse cursor is moved.

public event EventHandler<MouseHookEventArgs>? MouseMoved

Event Type

EventHandler<MouseHookEventArgs>
See Also

MousePressed

An event which is raised when a mouse button is pressed.

public event EventHandler<MouseHookEventArgs>? MousePressed

Event Type

EventHandler<MouseHookEventArgs>
See Also

MouseReleased

An event which is raised when a mouse button is released.

public event EventHandler<MouseHookEventArgs>? MouseReleased

Event Type

EventHandler<MouseHookEventArgs>
See Also

MouseWheel

An event which is raised when the mouse wheel is turned.

public event EventHandler<MouseWheelHookEventArgs>? MouseWheel

Event Type

EventHandler<MouseWheelHookEventArgs>
See Also

See Also