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 need method or group of them to send signals to any application (browsers, games, et cetera) about mouse movement or key input.

I can easly retrieve an IntPtr to any process, but I don't know what library or function I must use next.

I know only about SendMessage/PostMessage functions from user32.dll, but these functions can send messages only to applications with standard message loops and it doesn't work with DirectX applications. And I've noticed that something like this:

PostMessage(pFoundWindow, WM_KEYDOWN, (IntPtr)VK_RIGHT, (IntPtr)0);
PostMessage(pFoundWindow, WM_KEYUP, (IntPtr)VK_RIGHT, (IntPtr)0);  

sends messages slower than DirectInput in and does not allow player to send, for example, left arrow and space, even in threads.

share|improve this question
I answered this before, I just can't find the question. There is no 'universal' way unless you go as far as writing a mouse and keyboard driver that accepts commands from userspace. – Jonathan Dickinson Nov 8 '11 at 22:13
What you need to target today: Windows Input via PostMessage, DirectX via DLL Hooking (can't do this in C#) and XInput via DLL Hooking (can't do this in C#). – Jonathan Dickinson Nov 8 '11 at 22:14
Well, I can't believe that there is no way to send input to other application through C# and I'll try to continue research about them. Also, I have only one alternative C++ - is there are methods for this language? Please, give links to examples if you have it. – Dracontis Nov 9 '11 at 13:27
you can do it in C++ - but apart from knowing the universal method would be a 'virtual' mouse and keyboard I know nothing else. You will need to download the DDK (Windows Device Driver Kit) and start there. – Jonathan Dickinson Nov 9 '11 at 14:44
Thanks, I'll try to research that. – Dracontis Nov 9 '11 at 20:51

I am not sure what you can do about mouse movement. But for the keyboard, have you tried SendKeys?

I have a friend using SendKeys with speech recognition to do voice commands in StarCraft2. But I am not sure if it works with every game.

share|improve this answer
Yes, I tried SendKeys. It is hight level way, so this won't work in every game. For now I haven't time for research, but I think small application with WinAPI using DDK examples (create message loop and send equivalents of all messages to DDK driver) will solve my problem, but I do not start it yet. – Dracontis Dec 9 '11 at 15:24

You can create a simple script in like 2 minutes with AutoHotKey_L or AutoIt...
and then call the script in your C# project.

Both have support for almost any mouse/key movement or simulation you can think of.

share|improve this answer
I'll look at this applications. Maybe it's what I still need, because GlovePIE do what I want, but do it in ugly way. – Dracontis Feb 9 '12 at 19:19

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.