|
| 1 | +# SharpHook.R3 |
| 2 | + |
| 3 | +SharpHook provides a cross-platform global keyboard and mouse hook, event simulation, and text entry simulation for |
| 4 | +.NET. It is a wrapper of [libuiohook](https://github.com/TolikPylypchuk/libuiohook) and provides direct access to its |
| 5 | +features as well as higher-level types to work with it. |
| 6 | + |
| 7 | +If you're using [R3](https://github.com/Cysharp/R3), you can use the SharpHook.R3 package to integrate SharpHook with |
| 8 | +R3. |
| 9 | + |
| 10 | +## Usage |
| 11 | + |
| 12 | +### Basic Usage |
| 13 | + |
| 14 | +Refer to the [SharpHook](https://www.nuget.org/packages/SharpHook) package for the basic usage guidelines. |
| 15 | + |
| 16 | +### R3 Global Hooks |
| 17 | + |
| 18 | +SharpHook.R3 provides the `IR3GlobalHook` interface along with a default implementation and an adapter which you can use |
| 19 | +to use to control the global hook and subscribe to its observables. Here's a basic example: |
| 20 | + |
| 21 | +```c# |
| 22 | +using SharpHook.R3; |
| 23 | + |
| 24 | +// ... |
| 25 | +
|
| 26 | +var hook = new SimpleR3GlobalHook(); |
| 27 | + |
| 28 | +hook.HookEnabled.Subscribe(OnHookEnabled); |
| 29 | +hook.HookDisabled.Subscribe(OnHookDisabled); |
| 30 | + |
| 31 | +hook.KeyTyped.Subscribe(OnKeyTyped); |
| 32 | +hook.KeyPressed.Subscribe(OnKeyPressed); |
| 33 | +hook.KeyReleased.Subscribe(OnKeyReleased); |
| 34 | + |
| 35 | +hook.MouseClicked.Subscribe(OnMouseClicked); |
| 36 | +hook.MousePressed.Subscribe(OnMousePressed); |
| 37 | +hook.MouseReleased.Subscribe(OnMouseReleased); |
| 38 | + |
| 39 | +hook.MouseMoved |
| 40 | + .Debouce(TimeSpan.FromSeconds(0.5)) |
| 41 | + .Subscribe(OnMouseMoved); |
| 42 | + |
| 43 | +hook.MouseDragged |
| 44 | + .Debouce(TimeSpan.FromSeconds(0.5)) |
| 45 | + .Subscribe(OnMouseDragged); |
| 46 | + |
| 47 | +hook.MouseWheel.Subscribe(OnMouseWheel); |
| 48 | + |
| 49 | +hook.Run(); |
| 50 | +// or |
| 51 | +await hook.RunAsync(); |
| 52 | +``` |
| 53 | + |
| 54 | +R3 global hooks are basically the same as the default global hooks and the same rules apply to them. |
| 55 | + |
| 56 | +SharpHook.R3 provides two implementations of `IR3GlobalHook`: |
| 57 | + |
| 58 | +- `SharpHook.R3.SimpleR3GlobalHook`. Since we're dealing with observables, it's up to you to decide when and where to |
| 59 | +handle the events through time providers. A default time provider can be specified for all observables. |
| 60 | + |
| 61 | +- `SharpHook.R3.R3GlobalHookAdapter` adapts an `IGlobalHook` to `IR3GlobalHook`. All subscriptions and changes are |
| 62 | +propagated to the adapted hook. There is no default adapter from `IR3GlobalHook` to `IGlobalHook`. A default time |
| 63 | +provider can be specified for all observables. |
| 64 | + |
| 65 | +### Logging |
| 66 | + |
| 67 | +SharpHook.R3 contains `IR3LogSource` and `R3LogSourceAdapter` so you can use them in a more reactive way: |
| 68 | + |
| 69 | +```c# |
| 70 | +using SharpHook.Logging; |
| 71 | +using SharpHook.R3.Logging; |
| 72 | + |
| 73 | +// ... |
| 74 | +
|
| 75 | +var logSource = LogSource.RegisterOrGet(); |
| 76 | +var r3LogSource = new R3LogSourceAdapter(logSource); |
| 77 | +r3LogSource.MessageLogged.Subscribe(this.OnMessageLogged); |
| 78 | +``` |
| 79 | + |
| 80 | +### Rx.NET Integration |
| 81 | + |
| 82 | +As an alternative, SharpHook also provides integration with [Rx.NET](https://github.com/dotnet/reactive) in the |
| 83 | +[SharpHook.Reactive](https://www.nuget.org/packages/SharpHook.Reactive) package. |
| 84 | + |
| 85 | +## Icon |
| 86 | + |
| 87 | +Icon made by [Freepik](https://www.freepik.com) from [www.flaticon.com](https://www.flaticon.com). |
0 commit comments