Table of Contents

Class UioHook

Namespace
SharpHook.Native
Assembly
SharpHook.dll

Contains native methods of libuiohook.

public static class UioHook
Inheritance
UioHook
Inherited Members

Methods

CreateScreenInfo()

Gets the information about screens.

public static ScreenData[] CreateScreenInfo()

Returns

ScreenData[]

The information about screens.

Remarks

This is the safe version of CreateScreenInfo(out byte) as it returns a managed array.

See Also

CreateScreenInfo(out byte)

Gets the information about screens.

public static nint CreateScreenInfo(out byte count)

Parameters

count byte

The number of screens.

Returns

nint

The information about screens as an unmanaged array of ScreenData whose length is returned as count. The memory used by the array must be freed manually.

Remarks

You should use CreateScreenInfo() instead as it returns a managed array.

See Also

GetAutoRepeatDelay()

Gets the auto-repeat delay.

public static extern int GetAutoRepeatDelay()

Returns

int

The auto-repeat delay.

GetAutoRepeatRate()

Gets the auto-repeat rate.

public static extern int GetAutoRepeatRate()

Returns

int

The auto-repeat rate.

GetMultiClickTime()

Gets the multi-click time.

public static extern int GetMultiClickTime()

Returns

int

The multi-click time.

GetPointerAccelerationMultiplier()

Gets the pointer acceleration multiplier.

public static extern int GetPointerAccelerationMultiplier()

Returns

int

The pointer acceleration multiplier.

GetPointerAccelerationThreshold()

Gets the pointer acceleration threshold.

public static extern int GetPointerAccelerationThreshold()

Returns

int

The pointer acceleration threshold.

GetPointerSensitivity()

Gets the pointer sensitivity.

public static extern int GetPointerSensitivity()

Returns

int

The pointer sensitivity.

GetPostTextDelayX11()

Gets the delay (in nanoseconds) between posting individual characters when posting text on Linux.

public static extern ulong GetPostTextDelayX11()

Returns

ulong

The delay (in nanoseconds) between posting individual characters when posting text on Linux.

Remarks

X11 doesn't support posting arbitrary Unicode characters directly. Instead, for each character, an unused key code is remapped to that character, and then key press/release is simulated. Since the receiving application must react to the remapping, and may not do so instantaneously, a delay is needed for accurate simulation.

The default delay is 50 milliseconds.

On Windows and macOS this method always returns 0.

See Also

PostEvent(ref UioHookEvent)

Posts a fake input event.

public static UioHookResult PostEvent(ref UioHookEvent e)

Parameters

e UioHookEvent

The event to post.

Returns

UioHookResult

The result of the operation.

Remarks

The instance of the event doesn't need all fields to have value. Only Type, Keyboard/Mouse/Wheel should be present.

The following table describes the specifics of simulating each event type.

Event typeDescription
HookEnabledEvents of this type are ignored.
HookDisabledEvents of this type are ignored.
KeyPressedOnly KeyCode is considered.
KeyReleasedOnly KeyCode is considered.
KeyTyped Events of this type are ignored. PostText(string) should be used to post Unicode characters.
MousePressed Only X, Y, and Button are considered.
MouseReleased Only X, Y, and Button are considered.
MouseClickedEvents of this type are ignored.
MouseMovedOnly X and Y are considered.
MouseDraggedNot recommended to use; same as MouseMoved.
MouseWheel Only Rotation, Direction, and Type are considered.
See Also

PostText(string)

Simulates the input of arbitrary Unicode characters.

public static UioHookResult PostText(string text)

Parameters

text string

The text to simulate.

Returns

UioHookResult

The result of the operation.

Remarks

The text to simulate doesn't depend on the current keyboard layout. The full range of UTF-16 (including surrogate pairs, e.g. emojis) is supported.

On Windows text simulation should work correctly and consistently.

On macOS applications are not required to process text simulation, but most of them should handle it correctly.

X11 doesn't support text simulation directly. Instead, for each character, an unused key code is remapped to that character, and then key press/release is simulated. Since the receiving application must react to the remapping, and may not do so instantaneously, a delay is needed for accurate simulation. This means that text simulation on Linux works slowly and is not guaranteed to be correct. SetPostTextDelayX11(ulong) can be used to increase (or decrease) the delay if needed - longer dealys add consistency but may be more jarring to end users. GetPostTextDelayX11() can be used to get the currently configured delay - the default is 50 milliseconds.

See Also

Run()

Runs the global hook and blocks the thread until it's stopped.

public static extern UioHookResult Run()

Returns

UioHookResult

The result of the operation.

SetDispatchProc(DispatchProc?, nint)

Sets the hook callback function.

public static void SetDispatchProc(DispatchProc? dispatchProc, nint userData)

Parameters

dispatchProc DispatchProc

The function to call when an event is raised, or null to unset the function.

userData nint

Custom data to pass to the callback. Should not be used, and Zero should always be passed.

See Also

SetLoggerProc(LoggerProc?, nint)

Sets the log callback function.

public static void SetLoggerProc(LoggerProc? loggerProc, nint userData)

Parameters

loggerProc LoggerProc

The function to call for logging, or null to unset the function.

userData nint

Custom data to pass to the callback. Should not be used, and Zero should always be passed.

See Also

SetPostTextDelayX11(ulong)

Sets the delay (in nanoseconds) between posting individual characters when posting text on Linux.

public static extern void SetPostTextDelayX11(ulong delayNanoseconds)

Parameters

delayNanoseconds ulong

The delay (in nanoseconds) between posting individual characters when posting text on Linux.

Remarks

X11 doesn't support posting arbitrary Unicode characters directly. Instead, for each character, an unused key code is remapped to that character, and then key press/release is simulated. Since the receiving application must react to the remapping, and may not do so instantaneously, a delay is needed for accurate simulation.

The default delay is 50 milliseconds.

On Windows and macOS this method does nothing.

See Also

Stop()

Stops the global hook.

public static extern UioHookResult Stop()

Returns

UioHookResult

The result of the operation.