SharpHook.Reactive
1.0.0-preview.1
See the version list below for details.
dotnet add package SharpHook.Reactive --version 1.0.0-preview.1
NuGet\Install-Package SharpHook.Reactive -Version 1.0.0-preview.1
<PackageReference Include="SharpHook.Reactive" Version="1.0.0-preview.1" />
paket add SharpHook.Reactive --version 1.0.0-preview.1
#r "nuget: SharpHook.Reactive, 1.0.0-preview.1"
// Install SharpHook.Reactive as a Cake Addin #addin nuget:?package=SharpHook.Reactive&version=1.0.0-preview.1&prerelease // Install SharpHook.Reactive as a Cake Tool #tool nuget:?package=SharpHook.Reactive&version=1.0.0-preview.1&prerelease
SharpHook.Reactive
SharpHook is a library which provides a cross-platform global keyboard and mouse hook for .NET. It is a thin wrapper of libuiohook and provides direct access to its features as well as a higher-level interface and classes to work with it.
Supported Platforms
<table> <tr> <th></th> <th>Windows</th> <th>macOS</th> <th>Linux</th> </tr> <tr> <th>x86</th> <td>Yes</td> <td>N/A</td> <td>No<sup>1</sup></td> </tr> <tr> <th>x64</th> <td>Yes</td> <td>Yes</td> <td>Yes</td> </tr> <tr> <th>Arm32</th> <td>Yes<sup>2</sup></td> <td>N/A</td> <td>Yes</td> </tr> <tr> <th>Arm64</th> <td>No<sup>3</sup></td> <td>Yes</td> <td>Yes</td> </tr> </table>
[1] - Linux on x86 is not supported by .NET itself.
[2] - Windows Arm32 support was dropped in .NET 5 so it will most probably be dropped by this library in a future version as well.
[3] - Windows on Arm64 is not yet supported by libuiohook.
libuiohook only supports X11 on Linux. Wayland support may be coming, but it's not yet here.
Usage
Basic Usage
Referer to the SharpHook
package README for the basic usage guidelines.
Reactive Global Hooks
SharpHook.Reactive provides the IReactiveGlobalHook
interface along with a default implementation and an adapter
which you can use to use to control the hook and subscribe to its observables. Here's a basic example:
using SharpHook.Reactive;
// ...
var hook = new SimpleReactiveGlobalHook();
hook.HookEnabled.Subscribe(OnHookEnabled);
hook.HookDisabled.Subscribe(OnHookDisabled);
hook.KeyTyped.Subscribe(OnKeyTyped);
hook.KeyPressed.Subscribe(OnKeyPressed);
hook.KeyReleased.Subscribe(OnKeyReleased);
hook.MouseClicked.Subscribe(OnMouseClicked);
hook.MousePressed.Subscribe(OnMousePressed);
hook.MouseReleased.Subscribe(OnMouseReleased);
hook.MouseMoved
.Throttle(TimeSpan.FromSeconds(0.5))
.Subscribe(OnMouseMoved);
hook.MouseDragged
.Throttle(TimeSpan.FromSeconds(0.5))
.Subscribe(OnMouseDragged);
hook.MouseWheel.Subscribe(OnMouseWheel);
await hook.Start();
Reactive global hooks are basically the same as the default global hooks and the same rules apply to them.
SharpHook.Reactive provides two implementations of IReactiveGlobalHook
:
SimpleReactiveGlobalHook
runs the hook on a separate thread. Since we are dealing with observables, it's up to you to decide when and where to handle the events through schedulers.ReactiveGlobalHookAdapter
adapts anIGlobalHook
toIReactiveGlobalHook
. All subscriptions and changes are propagated to the adapted hook.
Limitations
You have to remember that libuiohook binaries should be present in the curent working directory. This is how P/Invoke works, and it can cause the 'library not found' issues when running your client app from a different directory.
Another thing is that libuiohook supports hooking into its logging capabilities so that you can get its logs. This
library doesn't support this. The reason is that you should call hook_set_logger_proc
and pass your callback for
logging. This is similar to hook_set_dispatch_proc
, but this time the callback should accept a variable number of
arguments (using C's ...
syntax) and the client decides how to format the log message. Supporting native
variable arguments in callbacks is next to impossible in C#, and the payoff is not worth spending a lot of effort to
implement this feature.
Icon
Icon made by Freepik from www.flaticon.com.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 is compatible. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 is compatible. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETCoreApp 3.1
- SharpHook (>= 1.0.0-preview.1)
- System.Reactive (>= 5.0.0)
-
.NETFramework 4.6.1
- SharpHook (>= 1.0.0-preview.1)
- System.Reactive (>= 5.0.0)
-
.NETStandard 2.0
- SharpHook (>= 1.0.0-preview.1)
- System.Reactive (>= 5.0.0)
-
net5.0
- SharpHook (>= 1.0.0-preview.1)
- System.Reactive (>= 5.0.0)
-
net6.0
- SharpHook (>= 1.0.0-preview.1)
- System.Reactive (>= 5.0.0)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on SharpHook.Reactive:
Package | Downloads |
---|---|
Strem.Core
Package Description |
|
Strem.Flows.Default
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
5.3.8 | 1,036 | 9/27/2024 |
5.3.7 | 1,016 | 7/9/2024 |
5.3.6 | 538 | 5/22/2024 |
5.3.5 | 158 | 5/20/2024 |
5.3.4 | 314 | 5/5/2024 |
5.3.3 | 148 | 4/28/2024 |
5.3.2 | 796 | 4/2/2024 |
5.3.1 | 736 | 3/3/2024 |
5.3.0 | 264 | 2/24/2024 |
5.2.3 | 527 | 2/1/2024 |
5.2.2 | 575 | 1/13/2024 |
5.2.1 | 218 | 1/3/2024 |
5.2.0 | 200 | 12/16/2023 |
5.1.2 | 1,137 | 11/25/2023 |
5.1.1 | 759 | 10/13/2023 |
5.1.0 | 174 | 10/8/2023 |
5.0.0 | 717 | 8/10/2023 |
4.2.1 | 1,403 | 6/18/2023 |
4.2.0 | 2,077 | 4/8/2023 |
4.1.0 | 357 | 3/26/2023 |
4.0.1 | 301 | 3/12/2023 |
4.0.0 | 1,037 | 11/9/2022 |
3.1.3 | 451 | 10/27/2022 |
3.1.2 | 439 | 10/19/2022 |
3.1.1 | 489 | 8/5/2022 |
3.1.0 | 424 | 7/30/2022 |
3.0.2 | 561 | 7/1/2022 |
3.0.1 | 409 | 6/25/2022 |
3.0.0 | 546 | 3/27/2022 |
2.0.0 | 733 | 2/4/2022 |
1.1.0 | 837 | 12/4/2021 |
1.0.1 | 656 | 11/21/2021 |
1.0.0 | 404 | 11/8/2021 |
1.0.0-preview.4 | 167 | 11/6/2021 |
1.0.0-preview.3 | 176 | 11/1/2021 |
1.0.0-preview.2 | 165 | 10/26/2021 |
1.0.0-preview.1 | 159 | 10/26/2021 |