mfakane / rawinput-sharp

C# wrapper library for Raw Input
zlib License
136 stars 34 forks source link

Hook keys #7

Open joedemax opened 4 years ago

joedemax commented 4 years ago

Hi.

Great library, works really well. How would I go about globally hooking a key?

Joe

mfakane commented 3 years ago

The Raw Input can catch key messages and identify it's source device, but doesn't have an ability to prevent other apps receiving key events, so you must use SetWindowsHookEx to do that.

If you want to combine Raw Input and global keyboard hooks, WH_KEYBOARD_LL can't be used; It will be called before the Raw Input, so you need to use WH_KEYBOARD. Very disappointingly, WH_KEYBOARD hooks can't be written in C#, so you need to write a native hook DLL that communicates to the host app that uses Raw Input to filter the received key events.

JustBrandonLim commented 2 years ago

Hi, I have another question! In my case, I would like to simulate inputs and clean it (INJECTED flags cleaned in WH_KEYBOARD_LL).

However, RawInput and DirectInput (D3D) do not get a HID from simulated inputs such as keybd_event or SendInput.

Is there a way to manipulate RawInput? Assuming RawInput is used by DirectInput (D3D).