Advertisement Jump to content
Sign in to follow this  

Simulating keystrokes for directx application

This topic is 2490 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() {
KEYBDINPUT keyB = {0};
keyB.wScan = DIKEY_DOWN;
keyB.dwFlags = KEYEVENTF_SCANCODE; = 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
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, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!