Table of Contents

Interface IEventSimulationProvider

Namespace
SharpHook.Providers
Assembly
SharpHook.dll

Represents a provider of low-level event simulation functionality.

public interface IEventSimulationProvider

Properties

PostTextDelayX11

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

ulong PostTextDelayX11 { get; set; }

Property Value

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 property does nothing and always returns 0.

Methods

PostEvent(ref UioHookEvent)

Posts a fake input event.

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

PostEvents(UioHookEvent[], uint)

Posts a sequence of fake input events.

UioHookResult PostEvents(UioHookEvent[] events, uint size)

Parameters

events UioHookEvent[]

The events to post.

size uint

The number of events to post.

Returns

UioHookResult

The result of the operation.

Remarks

All the same rules apply as to PostEvent(ref UioHookEvent).

See Also

PostText(string)

Simulates the input of arbitrary Unicode characters.

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 entry on Linux works slowly and is not guaranteed to be correct. PostTextDelayX11 can be used to get or set the delay if needed – longer delays add consistency but may be more jarring to end users – the default is 50 milliseconds.