Class UioHookProvider
A provider of low-level functionality which delegates it to the UioHook class.
[ExcludeFromCodeCoverage]
public sealed class UioHookProvider : ILoggingProvider, IGlobalHookProvider, IEventSimulationProvider, IAccessibilityProvider, IScreenInfoProvider, IMouseInfoProvider
- Inheritance
-
UioHookProvider
- Implements
- Inherited Members
Properties
AxPollFrequency
Gets or sets the frequency in seconds for polling the access to the macOS Accessibility API when the global hook is running. The default value is 1 second.
public uint AxPollFrequency { get; set; }
Property Value
- uint
The frequency in seconds for polling the access to the macOS Accessibility API when the global hook is running.
Remarks
On Windows and Linux, this property does nothing and always returns 0.
Instance
Gets the single instance of UioHookProvider.
public static UioHookProvider Instance { get; }
Property Value
KeyTypedEnabled
Gets or sets the value which indicates whether events of type KeyTyped are enabled. The default value is true.
public bool KeyTypedEnabled { get; set; }
Property Value
PostTextDelayX11
Gets or sets the delay (in nanoseconds) between posting individual characters when posting text on Linux.
public 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.
PromptUserIfAxApiDisabled
Gets or sets the value which indicates whether global hooks or event simulation should prompt the user when they try to request access to macOS Accessibility API, and it is disabled. The default value is true.
public bool PromptUserIfAxApiDisabled { get; set; }
Property Value
- bool
true if global hooks and event simulation should prompt the user for access to macOS Accessibility API when it is disabled. Otherwise, false.
Remarks
On Windows and Linux, this property does nothing and always returns false.
Methods
CreateScreenInfo()
Gets the information about screens.
public ScreenData[] CreateScreenInfo()
Returns
- ScreenData[]
The information about screens.
GetAutoRepeatDelay()
Gets the auto-repeat delay.
public int GetAutoRepeatDelay()
Returns
- int
The auto-repeat delay.
GetAutoRepeatRate()
Gets the auto-repeat rate.
public int GetAutoRepeatRate()
Returns
- int
The auto-repeat rate.
GetMultiClickTime()
Gets the multi-click time.
public int GetMultiClickTime()
Returns
- int
The multi-click time.
GetPointerAccelerationMultiplier()
Gets the pointer acceleration multiplier.
public int GetPointerAccelerationMultiplier()
Returns
- int
The pointer acceleration multiplier.
GetPointerAccelerationThreshold()
Gets the pointer acceleration threshold.
public int GetPointerAccelerationThreshold()
Returns
- int
The pointer acceleration threshold.
GetPointerSensitivity()
Gets the pointer sensitivity.
public int GetPointerSensitivity()
Returns
- int
The pointer sensitivity.
IsAxApiEnabled(bool)
Checks whether access to macOS Accessibility API is enabled for the process, optionally prompting the user if it is disabled.
public bool IsAxApiEnabled(bool promptUserIfDisabled)
Parameters
promptUserIfDisabledboolPrompt the user if access to macOS Accessibility API is disabled.
Returns
- bool
true if access to macOS Accessibility API is enabled for the process which means that global hooks and event simulation can be used. Otherwise, false.
Remarks
On Windows and Linux, this method does nothing and always returns true.
PostEvent(ref UioHookEvent)
Posts a fake input event.
public UioHookResult PostEvent(ref UioHookEvent e)
Parameters
eUioHookEventThe 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 type | Description |
|---|---|
| HookEnabled | Events of this type are ignored. |
| HookDisabled | Events of this type are ignored. |
| KeyPressed | Only KeyCode is considered. |
| KeyReleased | Only KeyCode is considered. |
| KeyTyped | Events of this type are ignored. |
| MousePressed | Only X, Y, and Button are considered. |
| MouseReleased | Only X, Y, and Button are considered. |
| MouseClicked | Events of this type are ignored. |
| MouseMoved | Only X and Y are considered. |
| MouseDragged | Not 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.
public UioHookResult PostEvents(UioHookEvent[] events, uint size)
Parameters
eventsUioHookEvent[]The events to post.
sizeuintThe 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 input of arbitrary Unicode characters.
public UioHookResult PostText(string text)
Parameters
textstringThe Unicode characters 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.
Run()
Runs the global hook and blocks the thread until it's stopped.
public UioHookResult Run()
Returns
- UioHookResult
The result of the operation.
RunKeyboard()
Runs the global hook only for keyboard events and blocks the thread until it's stopped.
public UioHookResult RunKeyboard()
Returns
- UioHookResult
The result of the operation.
Remarks
This method makes a difference only on Windows where there are two different global hooks – a keyboard hook and a mouse hook. On macOS and Linux, there is one hook for all events, and this method simply filters mouse events out at the libuiohook level on these OSes.
RunMouse()
Runs the global hook only for mouse events and blocks the thread until it's stopped.
public UioHookResult RunMouse()
Returns
- UioHookResult
The result of the operation.
Remarks
This method makes a difference only on Windows where there are two different global hooks – a keyboard hook and a mouse hook. On macOS and Linux, there is one hook for all events, and this method simply filters keyboard events out at the libuiohook level on these OSes.
SetDispatchProc(DispatchProc?, nint)
Sets the hook callback function.
public void SetDispatchProc(DispatchProc? dispatchProc, nint userData)
Parameters
dispatchProcDispatchProcThe function to call when an event is raised, or null to unset the function.
userDatanintCustom data to pass to the callback. Should not be used to pass pointers to objects, and Zero should usually be passed.
- See Also
SetLoggerProc(LoggerProc?, nint)
Sets the log callback function.
public void SetLoggerProc(LoggerProc? loggerProc, nint userData)
Parameters
loggerProcLoggerProcThe function to call for logging, or null to unset the function.
userDatanintCustom data to pass to the callback. Should not be used to pass pointers to objects, and Zero should usually be passed.
- See Also
Stop()
Stops the global hook.
public UioHookResult Stop()
Returns
- UioHookResult
The result of the operation.