Simulating keystrokes for directx application

Started by
0 comments, last by Prads 12 years, 1 month ago
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...
My first 3D game: Click Here
Advertisement
Whoops, nevermind. It's working now. I guess the sizeof(in) should have been sizeof(INPUT). Silly mistake. lol
My first 3D game: Click Here

This topic is closed to new replies.

Advertisement