Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to start develop for Kinect, but hardest theme for it - how to send keyboard and mouse input to any application. In previous question I got an advice to develop my own driver for this devices, but this will take a while.

I imagine application like a gate, that can translate SendMessage's into system wide input or driver application with API to send this inputs. So I wonder, is there are drivers or simulators that can interact with C# or C++?

Small edition: SendMessage, PostMessage, keybd_event will work only on Windows application with common messages loop. So I need driver application that will work on low, kernel, level.

share|improve this question
Sounds like you might be interested in software like Auto Hot Key that simulates key presses and the like to another application... not entirely sure however.. so just a comment. – James Nov 17 '11 at 23:38
Driver with API, that will simulate real keyboard. – Dracontis Nov 18 '11 at 9:10
You might have more luck on StackOverflow, this question is probably more low-level then the majority of users on here have experience in. I may be wrong. – dcousens Nov 18 '11 at 10:11
I can't ask questions on StackOverflow. – Dracontis Nov 18 '11 at 15:35
Why not? Stackoverflow is definitely a great place to post questions like this. – ultifinitus Nov 18 '11 at 20:51

For a C# Application:

To move the mouse, the Cursor class is our friend, as Cursor.Position can be used to move the mouse.

To simulate key-presses, The Sendkeys class is your friend, with SendKeys.Send() being used to simulate a keyboard press

For clicking the mouse, I know of no nice wrappers, but this code should work:

public static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);

public const int MOUSEEVENTF_LEFTDOWN = 0x02;
public const int MOUSEEVENTF_LEFTUP = 0x04;
public const int MOUSEEVENTF_RIGHTDOWN = 0x08;
public const int MOUSEEVENTF_RIGHTUP = 0x10;

public void MouseClick()
mouse_event(MOUSEEVENTF_LEFTDOWN, x, y, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, x, y, 0, 0);

(Just replace x and y with the actual mouse position, perhaps using the Cursor class again)

Alternatively, you can use something like the Global Mouse and Keyboard Library from CodeProject for a simple and clean interface to the whole process

share|improve this answer
Unfortunately this won't work for DirectInput/XInput applications. – Jonathan Dickinson Nov 18 '11 at 8:25
Events won't work in every application. Maybe sometimes game will be connected with common message loop and this library or function will work, but not in every one. I need driver-like application. – Dracontis Nov 18 '11 at 8:59

What you need is to create a system driver for a human interface device, HID. The previous advice to create a driver is correct because, as you noticed, you can't simply go stuffing events into higher level systems and get universal coverage.

You may want to start here: enter link description here and then continue looking around MSDN for driver samples to base your work from.

share|improve this answer
I also want to add that if you use the SendMessage approach you'll need UIAccess=true in your manifest to interact with applications that launched as Admin. Doing so requires that you have your code digitally signed (expensive). Writing a device driver is a better/more correct solution but it also requires a signed driver on x64. – NtscCobalt Jan 3 '12 at 16:48

Well, the best way to do such thing is to create your own keyboard/mouse driver using WDK. It's accurate and good looking solution, but it will take a lot of time if you're novice in programming.

Other solution is to use GlovePIE. You can write down your own script and then use it. So then you'll need to send message with your applicaton to GlovePIEand it will generate input on Kernel level, so this will work in DirectX games and message loop applications.

Well, really I want something like this, but with possibility to run as background process (GlovePIE start with window mode and then you can turn it) or maybe as library. If I found something else, I'll update answer.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.