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.

  • \$\begingroup\$ 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. \$\endgroup\$ – Jonathan Dickinson Nov 8 '11 at 22:13
  • \$\begingroup\$ 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#). \$\endgroup\$ – Jonathan Dickinson Nov 8 '11 at 22:14
  • \$\begingroup\$ 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. \$\endgroup\$ – Dracontis Nov 9 '11 at 13:27
  • 2
    \$\begingroup\$ 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. \$\endgroup\$ – Jonathan Dickinson Nov 9 '11 at 14:44
  • \$\begingroup\$ Answer to this question is the same as for gamedev.stackexchange.com/questions/19906/…. \$\endgroup\$ – Dracontis Jan 3 '12 at 16:32

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.

| improve this answer | |
  • \$\begingroup\$ 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. \$\endgroup\$ – 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.

| improve this answer | |
  • \$\begingroup\$ 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. \$\endgroup\$ – Dracontis Feb 9 '12 at 19:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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