Interface IEventSimulator
- Namespace
- SharpHook
- Assembly
- SharpHook.dll
Represents an object which can simulate keyboard and mouse events.
public interface IEventSimulator
Remarks
The methods of this interface correspond to constants defined in the EventType enum.
Properties
TextSimulationDelayOnX11
Gets or sets the delay between simulating individual characters when simulating text on Linux.
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.
Methods
SimulateKeyPress(KeyCode)
Simulates pressing a key.
UioHookResult SimulateKeyPress(KeyCode keyCode)
Parameters
keyCode
KeyCodeThe code of the key to press.
Returns
- UioHookResult
The result of the operation.
SimulateKeyRelease(KeyCode)
Simulates releasing a key.
UioHookResult SimulateKeyRelease(KeyCode keyCode)
Parameters
keyCode
KeyCodeThe code of the key to release.
Returns
- UioHookResult
The result of the operation.
SimulateMouseMovement(short, short)
Simulates moving a mouse pointer.
UioHookResult SimulateMouseMovement(short x, short y)
Parameters
x
shortThe target X-coordinate of the mouse pointer.
y
shortThe target Y-coordinate of the mouse pointer.
Returns
- UioHookResult
The result of the operation.
SimulateMouseMovementRelative(short, short)
Simulates moving a mouse pointer relative to the current cursor position.
UioHookResult SimulateMouseMovementRelative(short x, short y)
Parameters
Returns
- UioHookResult
The result of the operation.
SimulateMousePress(MouseButton)
Simulates pressing a mouse button at the current coordinates.
UioHookResult SimulateMousePress(MouseButton button)
Parameters
button
MouseButtonThe mouse button to press.
Returns
- UioHookResult
The result of the operation.
SimulateMousePress(short, short, MouseButton)
Simulates pressing a mouse button at the specified coordinates.
UioHookResult SimulateMousePress(short x, short y, MouseButton button)
Parameters
x
shortThe target X-coordinate of the mouse pointer.
y
shortThe target Y-coordinate of the mouse pointer.
button
MouseButtonThe mouse button to press.
Returns
- UioHookResult
The result of the operation.
SimulateMouseRelease(MouseButton)
Simulates releasing a mouse button at the current coordinates.
UioHookResult SimulateMouseRelease(MouseButton button)
Parameters
button
MouseButtonThe mouse button to release.
Returns
- UioHookResult
The result of the operation.
SimulateMouseRelease(short, short, MouseButton)
Simulates releasing a mouse button at the specified coordinates.
UioHookResult SimulateMouseRelease(short x, short y, MouseButton button)
Parameters
x
shortThe target X-coordinate of the mouse pointer.
y
shortThe target Y-coordinate of the mouse pointer.
button
MouseButtonThe mouse button to release.
Returns
- UioHookResult
The result of the operation.
SimulateMouseWheel(short, MouseWheelScrollDirection, MouseWheelScrollType)
Simulates scrolling the mouse wheel.
UioHookResult SimulateMouseWheel(short rotation, MouseWheelScrollDirection direction = MouseWheelScrollDirection.Vertical, MouseWheelScrollType type = MouseWheelScrollType.UnitScroll)
Parameters
rotation
shortThe 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
MouseWheelScrollDirectionThe scroll direction.
type
MouseWheelScrollTypeThe 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.
SimulateTextEntry(string)
Simulates the input of arbitrary Unicode characters.
UioHookResult SimulateTextEntry(string text)
Parameters
text
stringThe 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.