-
Notifications
You must be signed in to change notification settings - Fork 435
/
Copy pathHid.cs
159 lines (129 loc) · 5.03 KB
/
Hid.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Runtime.InteropServices;
// ReSharper disable InconsistentNaming
// (We are using the original names from the Windows API with type prefix removed.)
namespace osu.Framework.Platform.Windows.Native
{
internal class Hid
{
public const long HIDP_STATUS_SUCCESS = 0x00110000;
[DllImport("hid.dll")]
public static extern long HidP_GetCaps(IntPtr PreparsedData, out HIDP_CAPS Capabilities);
[DllImport("hid.dll")]
public static extern long HidP_GetValueCaps(HIDP_REPORT_TYPE ReportType, [Out] HIDP_VALUE_CAPS[] ValueCaps, ref ulong ValueCapsLength, IntPtr PreparsedData);
[DllImport("hid.dll")]
public static extern long HidP_GetLinkCollectionNodes([Out] HIDP_LINK_COLLECTION_NODE[] LinkCollectionNodes, ref ulong LinkCollectionNodesLength, IntPtr PreparsedData);
[DllImport("hid.dll")]
public static extern long HidP_GetUsageValue(
HIDP_REPORT_TYPE ReportType, ushort UsagePage, ushort LinkCollection, ushort Usage, out ulong UsageValue,
IntPtr PreparsedData, byte[] Report, ulong ReportLength);
[DllImport("hid.dll")]
public static extern long HidP_GetUsagesEx(
HIDP_REPORT_TYPE ReportType, ushort LinkCollection, [Out] USAGE_AND_PAGE[] ButtonList, ref ulong UsageLength,
IntPtr PreparsedData, byte[] Report, ulong ReportLength);
}
[StructLayout(LayoutKind.Sequential, Pack = 4)]
public struct HIDP_CAPS
{
public ushort Usage;
public ushort UsagePage;
public ushort InputReportByteLength;
public ushort OutputReportByteLength;
public ushort FeatureReportByteLength;
private unsafe fixed ushort Reserved[17];
public ushort NumberLinkCollectionNodes;
public ushort NumberInputButtonCaps;
public ushort NumberInputValueCaps;
public ushort NumberInputDataIndices;
public ushort NumberOutputButtonCaps;
public ushort NumberOutputValueCaps;
public ushort NumberOutputDataIndices;
public ushort NumberFeatureButtonCaps;
public ushort NumberFeatureValueCaps;
public ushort NumberFeatureDataIndices;
}
public enum HIDP_REPORT_TYPE
{
HidP_Input,
HidP_Output,
HidP_Feature
}
[StructLayout(LayoutKind.Sequential, Pack = 4)]
public struct HIDP_VALUE_CAPS
{
public ushort UsagePage;
public byte ReportID;
public byte IsAlias;
public ushort BitField;
public ushort LinkCollection;
public ushort LinkUsage;
public ushort LinkUsagePage;
public byte IsRange;
public byte IsStringRange;
public byte IsDesignatorRange;
public byte IsAbsolute;
public byte HasNull;
private byte Reserved;
public ushort BitSize;
public ushort ReportCount;
private unsafe fixed ushort Reserved2[5];
public uint UnitsExp;
public uint Units;
public int LogicalMin, LogicalMax;
public int PhysicalMin, PhysicalMax;
public Union union;
[StructLayout(LayoutKind.Explicit, Pack = 4)]
public struct Union
{
[FieldOffset(0)]
public _Range Range;
[FieldOffset(0)]
public _NotRange NotRange;
}
[StructLayout(LayoutKind.Sequential, Pack = 4)]
public struct _Range
{
public ushort UsageMin, UsageMax;
public ushort StringMin, StringMax;
public ushort DesignatorMin, DesignatorMax;
public ushort DataIndexMin, DataIndexMax;
}
[StructLayout(LayoutKind.Sequential, Pack = 4)]
public struct _NotRange
{
public ushort Usage;
private ushort Reserved1;
public ushort StringIndex;
private ushort Reserved2;
public ushort DesignatorIndex;
private ushort Reserved3;
public ushort DataIndex;
private ushort Reserved4;
}
}
[StructLayout(LayoutKind.Sequential, Pack = 4)]
public struct HIDP_LINK_COLLECTION_NODE
{
public ushort LinkUsage;
public ushort LinkUsagePage;
public ushort Parent;
public ushort NumberOfChildren;
public ushort NextSibling;
public ushort FirstChild;
// The original definition is:
// ULONG CollectionType: 8; // As defined in 6.2.2.6 of HID spec
// ULONG IsAlias : 1; // This link node is an allias of the next link node.
// ULONG Reserved: 23;
// Fortunately the value is not used here. Don't bother parsing the bitfield now.
public UInt32 _bitfield;
public IntPtr UserContext;
}
[StructLayout(LayoutKind.Sequential, Pack = 4)]
public struct USAGE_AND_PAGE
{
public ushort Usage;
public ushort UsagePage;
}
}