Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mfakane/rawinput-sharp
C# wrapper library for Raw Input
https://github.com/mfakane/rawinput-sharp
c-sharp rawinput
Last synced: 4 days ago
JSON representation
C# wrapper library for Raw Input
- Host: GitHub
- URL: https://github.com/mfakane/rawinput-sharp
- Owner: mfakane
- License: zlib
- Created: 2016-12-05T21:48:21.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2023-12-06T19:25:00.000Z (11 months ago)
- Last Synced: 2024-05-28T14:24:33.079Z (6 months ago)
- Topics: c-sharp, rawinput
- Language: C#
- Homepage:
- Size: 104 KB
- Stars: 132
- Watchers: 4
- Forks: 33
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE.txt
Awesome Lists containing this project
README
# RawInput.Sharp
A simple wrapper library for Windows [Raw Input](https://learn.microsoft.com/en-us/windows/win32/inputdev/raw-input).
Available on .NET Standard 1.1 and .NET Framework 4.6.1.## NuGet
https://www.nuget.org/packages/RawInput.Sharp/
## Usage
### Acquiring connected devices
```cs
// using Linearstar.Windows.RawInput;// Get the devices that can be handled with Raw Input.
var devices = RawInputDevice.GetDevices();// Keyboards will be returned as RawInputKeyboard.
var keyboards = devices.OfType();// Mice will be RawInputMouse.
var mice = devices.OfType();
```### Reading raw inputs
```cs
protected override void WndProc(ref Message m)
{
const int WM_INPUT = 0x00FF;// You can read inputs by processing the WM_INPUT message.
if (m.Msg == WM_INPUT)
{
// Create an RawInputData from the handle stored in lParam.
var data = RawInputData.FromHandle(m.LParam);// You can identify the source device using Header.DeviceHandle or just Device.
var sourceDeviceHandle = data.Header.DeviceHandle;
var sourceDevice = data.Device;// The data will be an instance of either RawInputMouseData, RawInputKeyboardData, or RawInputHidData.
// They contain the raw input data in their properties.
switch (data)
{
case RawInputMouseData mouse:
Console.WriteLine(mouse.Mouse);
break;
case RawInputKeyboardData keyboard:
Console.WriteLine(keyboard.Keyboard);
break;
case RawInputHidData hid:
Console.WriteLine(hid.Hid);
break;
}
}base.WndProc(ref m);
}
```### Further examples
- [RawInput.Sharp.SimpleExample](RawInput.Sharp.SimpleExample)
- A simple example that shows keyboard input events.
- [RawInput.Sharp.SimpleExample.WPF](RawInput.Sharp.SimpleExample.WPF)
- WPF version of the prior one.
- [RawInput.Sharp.DigitizerExample](RawInput.Sharp.DigitizerExample)
- An example handling digitizers, such as pen tablets, touch screens, and touch pads.## License
[zlib License](LICENSE.txt)