Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

Simulating keystrokes for directx application


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 Prads   Members   -  Reputation: 133

Like
0Likes
Like

Posted 27 March 2012 - 07:00 PM

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

Sponsor:

#2 Prads   Members   -  Reputation: 133

Like
0Likes
Like

Posted 27 March 2012 - 08:21 PM

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




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS