-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathLogRawInput.cs
53 lines (43 loc) · 1.29 KB
/
LogRawInput.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using UnityEngine;
using UnityRawInput;
public class LogRawInput : MonoBehaviour
{
public bool WorkInBackground;
public bool InterceptMessages;
private void OnEnable ()
{
RawInput.WorkInBackground = WorkInBackground;
RawInput.InterceptMessages = InterceptMessages;
RawInput.OnKeyUp += LogKeyUp;
RawInput.OnKeyDown += LogKeyDown;
RawInput.OnKeyDown += DisableIntercept;
RawInput.Start();
}
private void OnDisable ()
{
RawInput.Stop();
RawInput.OnKeyUp -= LogKeyUp;
RawInput.OnKeyDown -= LogKeyDown;
RawInput.OnKeyDown -= DisableIntercept;
}
private void OnValidate ()
{
// Apply options when toggles are clicked in editor.
// OnValidate is invoked only in the editor (won't affect build).
RawInput.InterceptMessages = InterceptMessages;
RawInput.WorkInBackground = WorkInBackground;
}
private void LogKeyUp (RawKey key)
{
Debug.Log("Key Up: " + key);
}
private void LogKeyDown (RawKey key)
{
Debug.Log("Key Down: " + key);
}
private void DisableIntercept (RawKey key)
{
if (RawInput.InterceptMessages && key == RawKey.Escape)
RawInput.InterceptMessages = InterceptMessages = false;
}
}