-
-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathRawInputKeyboardData.cs
32 lines (26 loc) · 944 Bytes
/
RawInputKeyboardData.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
using System.Runtime.InteropServices;
using Linearstar.Windows.RawInput.Native;
namespace Linearstar.Windows.RawInput
{
public class RawInputKeyboardData : RawInputData
{
public RawKeyboard Keyboard { get; }
public RawInputKeyboardData(RawInputHeader header, RawKeyboard keyboard)
: base(header) =>
Keyboard = keyboard;
public override unsafe byte[] ToStructure()
{
var headerSize = MarshalEx.SizeOf<RawInputHeader>();
var mouseSize = MarshalEx.SizeOf<RawKeyboard>();
var bytes = new byte[headerSize + mouseSize];
fixed (byte* bytesPtr = bytes)
{
*(RawInputHeader*)bytesPtr = Header;
*(RawKeyboard*)(bytesPtr + headerSize) = Keyboard;
}
return bytes;
}
public override string ToString() =>
$"{{{Header}, {Keyboard}}}";
}
}