You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For Unity 2017.4 and later: [UnityRawInput.unitypackage](https://github.com/Elringus/UnityRawInput/releases/download/v1.0/UnityRawInput.unitypackage).
3
+
4
+
## Description
5
+
Wrapper over [Windows Raw Input API](https://msdn.microsoft.com/en-us/library/windows/desktop/ms645536(v=vs.85).aspx) to hook for the native input events.
6
+
Allows to receive input events even when the Unity application is in background (not in focus).
7
+
Will only work on Windows platform.
8
+
9
+
## Usage
10
+
Include package namespace.
11
+
```csharp
12
+
usingUnityRawInput;
13
+
```
14
+
Initialize the input service to start processing native input messages.
15
+
```csharp
16
+
RawKeyInput.Start();
17
+
```
18
+
Optinally, you can specify whether input messages should be handled when the application is not in focus (disabled by default).
19
+
```csharp
20
+
varworkInBackground=true;
21
+
RawKeyInput.Start(workInBackground);
22
+
```
23
+
Add listeners for the input events.
24
+
```csharp
25
+
RawKeyInput.OnKeyUp+=HandleKeyUp;
26
+
RawKeyInput.OnKeyDown+=HandleKeyDown;
27
+
28
+
privatevoidHandleKeyUp (RawKeykey) { ... }
29
+
privatevoidHandleKeyDown (RawKeykey) { ... }
30
+
```
31
+
You can also check whether specific key is currently pressed.
32
+
```csharp
33
+
if (RawKeyInput.IsKeyDown(key)) { ... }
34
+
```
35
+
You can stop the service at any time.
36
+
```csharp
37
+
RawKeyInput.Stop();
38
+
```
39
+
Don't forget to remove listeners when you no longer need them.
0 commit comments