-
-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathHidButtonState.cs
33 lines (26 loc) · 869 Bytes
/
HidButtonState.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
using System;
using Linearstar.Windows.RawInput.Native;
namespace Linearstar.Windows.RawInput;
public class HidButtonState
{
readonly byte[] report;
readonly int reportLength;
public HidButton Button { get; }
public bool IsActive
{
get
{
using var preparsedDataPtr = Button.reader.GetPreparsedData();
var activeUsages = HidP.GetUsages(preparsedDataPtr, HidPReportType.Input, Button.buttonCaps, report, reportLength);
return Array.IndexOf(activeUsages, Button.UsageAndPage.Usage) != -1;
}
}
internal HidButtonState(HidButton button, byte[] report, int reportLength)
{
Button = button;
this.report = report;
this.reportLength = reportLength;
}
public override string ToString() =>
$"Button: {{{Button}}}, IsActive: {IsActive}";
}