-
-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathProgram.cs
More file actions
42 lines (34 loc) · 1.21 KB
/
Program.cs
File metadata and controls
42 lines (34 loc) · 1.21 KB
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
using System;
using System.Linq;
using System.Windows.Forms;
using Linearstar.Windows.RawInput;
using RawInput.Sharp.SimpleExample;
// Get the devices that can be handled with Raw Input.
var devices = RawInputDevice.GetDevices();
// Keyboards will be returned as a RawInputKeyboard.
var keyboards = devices.OfType<RawInputKeyboard>();
// List them up.
foreach (var device in keyboards)
Console.WriteLine(
$"{device.DeviceType} {device.VendorId:X4}:{device.ProductId:X4} {device.ProductName}, {device.ManufacturerName}");
// To begin catching inputs, first make a window that listens WM_INPUT.
var window = new RawInputReceiverWindow();
window.Input += (sender, e) =>
{
// Catch your input here!
var data = e.Data;
Console.WriteLine(data);
};
try
{
// Register the HidUsageAndPage to watch any device.
RawInputDevice.RegisterDevice(HidUsageAndPage.Keyboard,
RawInputDeviceFlags.ExInputSink | RawInputDeviceFlags.NoLegacy, window.Handle);
RawInputDevice.RegisterDevice(HidUsageAndPage.Mouse,
RawInputDeviceFlags.ExInputSink | RawInputDeviceFlags.NoLegacy, window.Handle);
Application.Run();
}
finally
{
RawInputDevice.UnregisterDevice(HidUsageAndPage.Keyboard);
}