Simulate KeyPress

Apr 26, 2011 at 2:36am
I am a novice at c++ so please excuse my basic questions. I have a custom game controller that I can get data from using a small c++ console program. I want to convert some of the input to mouse and some to keypresses. So far I have it working OK, using INPUT and SendInput. If I open a notepad I can see all of the keypresses written to the page. I can also move the mouse and make button presses OK too. But when I start a game, the mouse part of it works OK, ie moving the cursor and the mouse buttons work too, but the keypresses are not getting through. Any idea how I can get my keypresses to be recognised by a game? Any help will be greatly appreciated.
Apr 26, 2011 at 2:55am
Check out my blog. (which really needs updating)

http://ultifinitus.blogspot.com/2011/04/first-post.html
Apr 26, 2011 at 5:05am
Thanks for the link. I have tried using keybd_event which worked fine when focus was on a notepad, but still didn't work in a game. Admittedly I only tried 2 older games, Quake 3 Arena and Serious Sam 2.
Apr 26, 2011 at 12:49pm
Have you tried with the hardware codes instead of VK_Key codes?
Apr 26, 2011 at 1:00pm
According to some guy on the internet:

A sure fire way would be to write a Virtual Device Driver (VxD) that inserts key strokes directly into the keyboard buffer, fooling DirectInput. Another way, like you said, is to write a DLL that injects code into the DirectInput memory space.

Looking through the Microsoft DDK, there are examples of custom VxD files. Under keyb\samples\Vkxd\ there is an example of an easy keyboard emulation VxD. But that might be outdated. DirectInput deals directly with the keyboard buffer (and other devices) and completely ignores all input that has been passed through windows and converted into WM_* messages. So any sort of WM_* simulation will not work.


Wow... Just learned how to inject dlls, horrific. This method is guaranteed to work, however it's more difficult than most programming you'll come across
Topic archived. No new replies allowed.