Skip to content

Commit cfe1e73

Browse files
authored
create readme
1 parent 606cf20 commit cfe1e73

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
## Download package
2+
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+
using UnityRawInput;
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+
var workInBackground = 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+
private void HandleKeyUp (RawKey key) { ... }
29+
private void HandleKeyDown (RawKey key) { ... }
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.
40+
```csharp
41+
private void OnDisable ()
42+
{
43+
RawKeyInput.OnKeyUp -= HandleKeyUp;
44+
RawKeyInput.OnKeyDown -= HandleKeyDown;
45+
}
46+
```

0 commit comments

Comments
 (0)