Skip to content

Commit 1e55cbb

Browse files
committed
Use bitwise operators rather than blockcopy
1 parent 85e62cd commit 1e55cbb

2 files changed

Lines changed: 7 additions & 8 deletions

File tree

HID-API/HidHandler.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,7 @@ public void WriteMouseReport(Mouse mouse, FileStream fileStream)
124124
(mouse.FiveButton ? 16 : 0));
125125

126126
sbyte wheel = (sbyte) mouse.Wheel;
127-
128-
WriteUtils.WriteMouseReport(fileStream,
129-
1,
130-
buttonByte,
131-
new[] {mouse.X, mouse.Y},
132-
wheel);
127+
WriteUtils.WriteMouseReport(fileStream, 1, buttonByte, mouse.X, mouse.Y, wheel);
133128
}
134129

135130
public void WriteKeyboardReport(Keyboard keyboard, FileStream fileStream)

HID-API/Utils/WriteUtils.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,18 @@ public static void WriteKeyboardReport(FileStream stream, Keyboard keyboard)
2929
stream.Flush();
3030
}
3131

32-
public static void WriteMouseReport(FileStream stream, byte reportId, byte bytes, short[] shorts, sbyte signedByte)
32+
public static void WriteMouseReport(FileStream stream, byte reportId, byte bytes, short x, short y, sbyte signedByte)
3333
{
3434
byte[] buffer = new byte[7];
3535

3636
buffer[0] = reportId;
3737
buffer[1] = bytes;
3838

39-
Buffer.BlockCopy(shorts, 0, buffer, 2, 4);
39+
buffer[2] = (byte) (x & 0xff);
40+
buffer[3] = (byte) ((x >> 8) & 0xff);
41+
buffer[4] = (byte) (y & 0xff);
42+
buffer[5] = (byte) ((y >> 8) & 0xff);
43+
4044
buffer[6] = (byte)signedByte;
4145

4246
stream.Write(buffer, 0, 7);

0 commit comments

Comments
 (0)