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 : BasicGlobalHookBase, IGlobalHook, IBasicGlobalHook, IDisposable
Inheritance
GlobalHookBase
Implements
Derived
Inherited Members

Constructors

GlobalHookBase(GlobalHookType, IGlobalHookProvider?, bool)

Initializes a new instance of GlobalHookBase.

protected GlobalHookBase(GlobalHookType globalHookType = GlobalHookType.All, IGlobalHookProvider? globalHookProvider = null, bool runAsyncOnBackgroundThread = false)

Parameters

globalHookType GlobalHookType

The global hook type.

globalHookProvider IGlobalHookProvider

The underlying global hook provider, or null to use the default one.

runAsyncOnBackgroundThread bool

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

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.

HandleHookEvent(ref UioHookEvent)

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

protected override 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. They can also call ShouldDispatchEvent(ref UioHookEvent) to determine whether to attempt dispatching the event at all.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

ShouldDispatchEvent(ref UioHookEvent)

Returns a value which indicates whether there are any subscribers to an event which corresponds to the hook event type.

protected bool ShouldDispatchEvent(ref UioHookEvent e)

Parameters

e UioHookEvent

The event to check.

Returns

bool

true if there are any subscribers to an event which corresponds to the hook event type. Otherwise, false.

Remarks

Derived classes may call this method as an optimization before attempting to dispatch the hook event.

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.

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.

KeyPressed

An event which is raised when a key is pressed.

public event EventHandler<KeyboardHookEventArgs>? KeyPressed

Event Type

EventHandler<KeyboardHookEventArgs>

KeyReleased

An event which is raised when a key is released.

public event EventHandler<KeyboardHookEventArgs>? KeyReleased

Event Type

EventHandler<KeyboardHookEventArgs>

KeyTyped

An event which is raised when a key is typed.

public event EventHandler<KeyboardHookEventArgs>? KeyTyped

Event Type

EventHandler<KeyboardHookEventArgs>

MouseClicked

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

public event EventHandler<MouseHookEventArgs>? MouseClicked

Event Type

EventHandler<MouseHookEventArgs>

MouseDragged

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

public event EventHandler<MouseHookEventArgs>? MouseDragged

Event Type

EventHandler<MouseHookEventArgs>

MouseMoved

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

public event EventHandler<MouseHookEventArgs>? MouseMoved

Event Type

EventHandler<MouseHookEventArgs>

MousePressed

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

public event EventHandler<MouseHookEventArgs>? MousePressed

Event Type

EventHandler<MouseHookEventArgs>

MouseReleased

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

public event EventHandler<MouseHookEventArgs>? MouseReleased

Event Type

EventHandler<MouseHookEventArgs>

MouseWheel

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

public event EventHandler<MouseWheelHookEventArgs>? MouseWheel

Event Type

EventHandler<MouseWheelHookEventArgs>

See Also