12

here is my situation: we are writing an application that must transform Microsoft Kinect coordinates into keyboard and mouse events.

When we need to take control of the mouse, everything works as we intended in ANY kind of application. The problem arises when we need to send keyboard events (like key down or key up) to applications that doesn't handle Windows events, like games, for example.

We tried the SendKeys class of the .net framework, and it only works with Windows applications. When the application is a game like Half-Life or Doom we can't get the same effect. So, here is my question: how can we effectively send keyboard events to these other applications?

Kico Lobo
  • 4,374
  • 4
  • 35
  • 48

5 Answers5

3

You need to simulate input using SendInput. SendMessage and SendKeys tend to work at the level of windows messages - but DirectX apps don't run a traditional message loop.

There is a page on PInvoke.NET, but I have to confess, I've not tried to use it.


See also this thread on the GameDev.net site, where someone has worked with some of the "teething" issues that can be encountered specifically interacting with a DirectInput based application.

Damien_The_Unbeliever
  • 234,701
  • 27
  • 340
  • 448
2

Unfortunately DirectX has no built-in hooking functionality; however there are some (this one is a .Net wrapper over another one) libraries out there that can do it. You will also need to look into XInput, which deprecates DirectInput.

sehe
  • 374,641
  • 47
  • 450
  • 633
Jonathan Dickinson
  • 9,050
  • 1
  • 37
  • 60
  • 1
    No, the idea of this form of hooking is that you inject your own code into the application before it has the opportunity to create the object AT RUNTIME. This new code will cause your own object to be created. That is why it has to be in C/++ (but there is a .Net wrapper there). Also remember that this type of hooking will make cheat monitors(e.g. Punk Buster) go absolutely bonkers. – Jonathan Dickinson Aug 23 '11 at 13:46
1

I think following post should be an answer to your question,

How do i send keys using a global keyboard hook?

According to the answer, you have to use following key codes to the SendInput function, http://www.gamespp.com/directx/directInputKeyboardScanCodes.html

Community
  • 1
  • 1
Low Flying Pelican
  • 5,974
  • 1
  • 32
  • 43
0

You need to pInvoke Winapi sendmessage.

http://msdn.microsoft.com/en-us/library/ms644950(v=vs.85).aspx

http://pinvoke.net/default.aspx/user32.SendMessage

This is what I'm using. It works but you have to read a little bit about it. This is very powerful method.

Hooch
  • 28,817
  • 29
  • 102
  • 161
  • SendMessage is not a good solution either :( Already tried that too and didn't work as I wanted. As InputSimulator, it didn't send input to game applications either. :( – Kico Lobo Aug 23 '11 at 13:19
0

This is a quick and easy solution that I'm using. Works well.

InputSimulator

Will Calderwood
  • 4,393
  • 3
  • 39
  • 64
  • Alrady tried that :( Works fine for "traditional" Windows applications, but when sending inputs to applications like "Half-Life" or "Doom" it simply doesn't work. – Kico Lobo Aug 23 '11 at 13:13