Table of Contents

Class EventSimulator

Namespace
SharpHook
Assembly
SharpHook.dll

A keyboard and mouse event simulator which posts events to a simulation provider (libuiohook by default).

public class EventSimulator : IEventSimulator
Inheritance
EventSimulator
Implements
Inherited Members

Constructors

EventSimulator()

Initializes a new instance of the EventSimulator class.

public EventSimulator()
See Also

EventSimulator(IEventSimulationProvider)

Initializes a new instance of the EventSimulator class.

public EventSimulator(IEventSimulationProvider simulationProvider)

Parameters

simulationProvider IEventSimulationProvider

The simulation functionality provider.

Exceptions

ArgumentNullException

simulationProvider is null.

See Also

Properties

TextSimulationDelayOnX11

Gets or sets the delay between simulating individual characters when simulating text on Linux.

public TimeSpan TextSimulationDelayOnX11 { get; set; }

Property Value

TimeSpan

The delay between simulating individual characters when simulating text on Linux.

Remarks

X11 doesn't support simulating 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 is ignored.

Exceptions

ArgumentOutOfRangeException

value represents a negative time span.

See Also

Methods

SimulateKeyPress(KeyCode)

Simulates pressing a key.

public UioHookResult SimulateKeyPress(KeyCode keyCode)

Parameters

keyCode KeyCode

The code of the key to press.

Returns

UioHookResult

The result of the operation.

See Also

SimulateKeyRelease(KeyCode)

Simulates releasing a key.

public UioHookResult SimulateKeyRelease(KeyCode keyCode)

Parameters

keyCode KeyCode

The code of the key to release.

Returns

UioHookResult

The result of the operation.

See Also

SimulateMouseMovement(short, short)

Simulates moving a mouse pointer.

public UioHookResult SimulateMouseMovement(short x, short y)

Parameters

x short

The target X-coordinate of the mouse pointer.

y short

The target Y-coordinate of the mouse pointer.

Returns

UioHookResult

The result of the operation.

See Also

SimulateMouseMovementRelative(short, short)

Simulates moving a mouse pointer relative to the current cursor position.

public UioHookResult SimulateMouseMovementRelative(short x, short y)

Parameters

x short

The X-coordinate offset.

y short

The Y-coordinate offset.

Returns

UioHookResult

The result of the operation.

See Also

SimulateMousePress(MouseButton)

Simulates pressing a mouse button at the current coordinates.

public UioHookResult SimulateMousePress(MouseButton button)

Parameters

button MouseButton

The mouse button to press.

Returns

UioHookResult

The result of the operation.

See Also

SimulateMousePress(short, short, MouseButton)

Simulates pressing a mouse button at the specified coordinates.

public UioHookResult SimulateMousePress(short x, short y, MouseButton button)

Parameters

x short

The target X-coordinate of the mouse pointer.

y short

The target Y-coordinate of the mouse pointer.

button MouseButton

The mouse button to press.

Returns

UioHookResult

The result of the operation.

See Also

SimulateMouseRelease(MouseButton)

Simulates releasing a mouse button at the current coordinates.

public UioHookResult SimulateMouseRelease(MouseButton button)

Parameters

button MouseButton

The mouse button to release.

Returns

UioHookResult

The result of the operation.

See Also

SimulateMouseRelease(short, short, MouseButton)

Simulates releasing a mouse button at the specified coordinates.

public UioHookResult SimulateMouseRelease(short x, short y, MouseButton button)

Parameters

x short

The target X-coordinate of the mouse pointer.

y short

The target Y-coordinate of the mouse pointer.

button MouseButton

The mouse button to release.

Returns

UioHookResult

The result of the operation.

See Also

SimulateMouseWheel(short, MouseWheelScrollDirection, MouseWheelScrollType)

Simulates scrolling the mouse wheel.

public UioHookResult SimulateMouseWheel(short rotation, MouseWheelScrollDirection direction = MouseWheelScrollDirection.Vertical, MouseWheelScrollType type = MouseWheelScrollType.UnitScroll)

Parameters

rotation short

The wheel rotation. A positive value indicates that the wheel will be rotated up or left, and a negative value indicates that the wheel will be rotated down or right.

direction MouseWheelScrollDirection

The scroll direction.

type MouseWheelScrollType

The scroll type (considered only on macOS).

Returns

UioHookResult

The result of the operation.

Remarks

On Windows the value 120 represents the default wheel step. As such, multiples of 120 can be used, but it's not required. The value of type is ignored.

On macOS it's recommended to use values between -10 and 10. This will result in quite a small scroll amount with pixel scrolling, so BlockScroll is recommended for line scrolling instead of pixel scrolling.

On Linux there is no fixed recommendation, but multiples of 100 can be used. The value of type is ignored.

See Also

SimulateTextEntry(string)

Simulates the input of arbitrary Unicode characters.

public UioHookResult SimulateTextEntry(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. TextSimulationDelayOnX11 can be used to increase (or decrease) the delay if needed - longer delays add consistency but may be more jarring to end users. TextSimulationDelayOnX11 can also be used to get the currently configured delay - the default is 50 milliseconds.

Exceptions

ArgumentNullException

text is null.

See Also

See Also