Jump to content
  • Advertisement
Sign in to follow this  
Jacob Roman

SendKeys using DirectInput

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 it possible to do something similar to SendKeys only using DirectInput? And if so, how do I do it? For those of you who don't know, SendKeys is like automatic keypresses of whatever text you want without the user touching the keyboard.

Share this post


Link to post
Share on other sites
Advertisement
There's no way to do that. What do you want to do? If you want to simulate the user pressing the keys in your own game, then just call the code that's supposed to run when the user presses the keys.

Share this post


Link to post
Share on other sites
Are you sure? I'm thinking that this could be one of the methods of Action Mapping. But in my case, I'm gonna be using it for a non game related purpose. Might come in handy for different things. Does anyone else agree or can it be possible?

Share this post


Link to post
Share on other sites
SendInput() injects at a lower level than DirectInput, so the input that you send using SendInput() will be picked up by your DirectInput devices.

Share this post


Link to post
Share on other sites
Quote:
Original post by jacklin
SendInput() injects at a lower level than DirectInput, so the input that you send using SendInput() will be picked up by your DirectInput devices.

Thanks for the information, this is news to me [smile]

Share this post


Link to post
Share on other sites
I have a function:
//******************************************************
static void SendString(LPCTSTR str)
{
INPUT inp[2];
memset(inp,0,sizeof(INPUT));
inp[0].type = INPUT_KEYBOARD;
inp[0].ki.dwFlags = KEYEVENTF_UNICODE; // to avoid shift, etc.
inp[1] = inp[0];
inp[1].ki.dwFlags |= KEYEVENTF_KEYUP;

for (LPCTSTR p=str; *p; p++) {
inp[0].ki.wScan = inp[1].ki.wScan = *p;
SendInput(2, inp, sizeof(INPUT));
}
}
//********************************************************

I use Keyboard_2003 sample from DX 9 SDK (June 2005) to test it. When I send a string like "a" nothing seems to happen. Am I doing something wrong? It works with apps that don't use DInput.

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!