Jump to content
  • Advertisement
Sign in to follow this  
Spasojevic

Sending keystrokes to DInput from external app

This topic is 4836 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is there a way to send keystrokes to a game using direcinput from an external app running in background. I have an USB HID device that will send input, and my app should send this input to a game in form of keystrokes?

Share this post


Link to post
Share on other sites
Advertisement
I can't really say that I know for sure, but I'm quite certain that DirectInput works on a low level with the keyboard. And considering this you can not send input to it in any way. The thing you could do is send a Windows message from one app to another that features the pressed key as a message, and then handle it as if the correspondeing key in DirectInput had been pressed...

Share this post


Link to post
Share on other sites
Problem is that I want to send input to games already made by others. My app should be something like user mode driver, but I don't want to go into driver development. Apps like Total Game Control do something like that. This is for my final exam and the time is running out...

Share this post


Link to post
Share on other sites
SendInput function is the right answer. Correct way to use it with DInput is something like this:
//*********************************************************
// Sets a button to down state
static void SetInputDX(WORD input_code_set)
{
INPUT inp[1];
memset(inp,0,sizeof(INPUT));
inp[0].type = INPUT_KEYBOARD;
inp[0].ki.wScan = input_code_set;
SendInput(1, inp, sizeof(INPUT));

}
//*********************************************************
// Sets a button to up state
static void ReleaseInputDX(WORD input_code_release)
{
INPUT inp[1];
memset(inp,0,sizeof(INPUT));
inp[0].type = INPUT_KEYBOARD;
inp[0].ki.dwFlags |= KEYEVENTF_KEYUP;
inp[0].ki.wScan = input_code_release;
SendInput(1, inp, sizeof(INPUT));

}

For DInput to see these codes properly you should pass DInput constants like:
DIKEYBOARD_A but only first two bytes (letter "a" is 0x041e , and so on).
I'we tried this, it realy works.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!