Open malware-dev opened 6 years ago
SharpDX creates new instance of KeyboardInputEventArgs which causes garbage.
https://github.com/sharpdx/SharpDX/blob/8dc1f64a9424c6b0dc8b9009f70e144ded03f1d7/Source/SharpDX.RawInput/Device.cs, inside HandleMessage method.
Yep, I have the same problem on 4.2.0 and 4.1.0, on the 4.0.1 everything works perfectly fine
Got the same problem seems to work with 4.1.0-ci217 but as of 4.1.0 it only returns weird values.
It looks like the data coming back from user32 is ok, but the RawInput struct is ordered incorrectly:
Header size is 24 so the bottom watch value should be where MakeCode lives. However it is 17 when I thought it would be 18 (I think I hit w, but maybe I hit q by accident?).
There's alot of strange generated code for this stuff that I can't fathom yet so I need to do some more digging.
Generated code for RawInput.Data union handling changed from "Explicit+FieldOffset" (v4.0.1) to "Native sub struct marshalling", therefore "HandleMessage" should use "MarshalFrom":
var rawInput = default(RawInput);
rawInput.__MarshalFrom(ref *(RawInput.__Native*)rawInputDataPtr);
switch (rawInput.Header.Type)
{
case DeviceType.HumanInputDevice:
RawInput?.Invoke(null, new HidInputEventArgs(ref rawInput, hwnd));
break;
case DeviceType.Keyboard:
KeyboardInput?.Invoke(null, new KeyboardInputEventArgs(ref rawInput, hwnd));
break;
case DeviceType.Mouse:
MouseInput?.Invoke(null, new MouseInputEventArgs(ref rawInput, hwnd));
break;
}
or revert back to "Explicit+FieldOffset"
@jkoritzinsky Could you have a look at this codegen issue?
This is still an issue, I'm forced to revert to 4.0.1 for now
I am getting seemingly garbage data when attempting to get keyboard input. Am I doing something stupid?
Output: (x64-build, pressing keys wildly)
Output: (AnyCPU build, pressing esc only)