[C++] DirectInput Hooking component and sample

Started by
2 comments, last by badboy3000 11 years, 10 months ago
This sample demonstrates using DirectInput hooking to send key-presses to DirectInput-based applications, mostly games. It is actually more like a component in that it can readily be used as is, you'll just have to write client applications. The main component is DirectInput-Hook.dll. This DLL exports 2 functions, InstallHook and RemoveHook. The first instructs the DLL to start inspecting the names of all processes loaded afterwards in search for a specific process, and then injecting code into that process to override DirectInput8Create. The process name is specified in a registry key, HKEY_CURRENT_USER\Software\Dinput-Hook. The DLL component intercepts requests to create GUID_SysKeyboard devices and returns a special keyboard device instead. This special keyboard device, on initialization, creates a pipe named "DInput-Pipe". Whenever IDirectInputDevice8::GetDeviceState is called to retrieve the state of the keyboard in immediate mode, the keyboard checks the pipe for any pending messages, reads them, parses them to determine what key-presses to simulate, and returns a keyboard state containing the simulated key-presses. Message format is straight-forward: Strings containing space-seperated lists of integral scan-codes; the values for DIK_* constants. Nothing is done with buffered input. You're free to modify the code if you like, you'll find a couple of hints in the comments. Important things to keep in mind: 1. You must keep the DLL loaded while the target application hasn't stopped using DirectInput. Otherwise, our DirectInput interface implementor objects will be unloaded and the target application will crash. 2. Put the target process name in the registry, and call InstallHook before launching the target process. A sample client application is provided - all it does is hook "Keyboard.exe", one of the DirectInput samples included in the SDK, and sends it 4 key-presses all the time: Escape, 1, 2 and 3. As always, my code is public domain. APIHijack, the hooking library, is not. Contact its author for license details. 2003 and 2005 solutions are included.

Advertisement
Looks good to me, will see about having a proper look when I've got a bit more free time! I presume this is the final results of what you mentioned in this thread: Help Needed - DirectX and SendKeys?

I'll sticky this for a while so that it gets the attention it deserves [smile]

(Although, that means I'll have to tidy things up around here...)

Keep up the good work!

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

does anyone have a local copy of this sample? I really would like to see it but the link is dead.
[href]http://whileboredblog.blogspot.com/[/href] - My Development Blog
Who can upload this sample?

This topic is closed to new replies.

Advertisement