-
-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathHidButtonSetState.cs
40 lines (32 loc) · 1.23 KB
/
HidButtonSetState.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
using System.Collections;
using System.Collections.Generic;
using Linearstar.Windows.RawInput.Native;
namespace Linearstar.Windows.RawInput;
public class HidButtonSetState : IEnumerable<HidButtonState>
{
readonly byte[] report;
readonly int reportLength;
public HidButtonSet ButtonSet { get; }
public ushort[] ActiveUsages
{
get
{
using var preparsedDataPtr = ButtonSet.reader.GetPreparsedData();
return HidP.GetUsages(preparsedDataPtr, HidPReportType.Input, ButtonSet.buttonCaps, report, reportLength);
}
}
internal HidButtonSetState(HidButtonSet buttonSet, byte[] report, int reportLength)
{
ButtonSet = buttonSet;
this.report = report;
this.reportLength = reportLength;
}
public override string ToString() =>
$"ButtonSet: {{{ButtonSet}}}, Active: [{string.Join(", ", ActiveUsages)}]";
public IEnumerator<HidButtonState> GetEnumerator()
{
for (var usage = ButtonSet.UsageMin; usage <= ButtonSet.UsageMax; usage++)
yield return new HidButtonState(new HidButton(ButtonSet.reader, ButtonSet.buttonCaps, usage), report, reportLength);
}
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}