Jump to content
  • Advertisement
Sign in to follow this  
Prads

Simulating keystrokes for directx application

This topic is 2337 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

Hello, I am trying to create a keystorke simulator to control games like NFS World. I tried using SendInpu, and it works great for notepad and explorer window but doesn't for for directx applications. Here my code, it sends DOWN key every 1 second:


#include <Windows.h>
#pragma comment (lib, "Winmm.lib")
#define DIKEY_DOWN 0x04D0
int main() {
INPUT in;
KEYBDINPUT keyB = {0};
in.type = INPUT_KEYBOARD;
keyB.wScan = DIKEY_DOWN;
keyB.dwFlags = KEYEVENTF_SCANCODE;
in.ki = keyB;
DWORD prevTime = timeGetTime();
DWORD currTime;
while (true) {
if (GetAsyncKeyState(VK_ESCAPE) & 0x8000) break;
currTime = timeGetTime();
if ((currTime - prevTime) >= 1000) {
SendInput(1, &in, sizeof(in));
prevTime = currTime;
}
}
return 0;
}


I am testing this code in Windows 7.

So, are there anyway to simulate key that works for directx applications? Thanks...

Share this post


Link to post
Share on other sites
Advertisement
Whoops, nevermind. It's working now. I guess the sizeof(in) should have been sizeof(INPUT). Silly mistake. lol

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!