3
\$\begingroup\$

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);
Thread.Sleep(150);
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.

\$\endgroup\$
5
  • \$\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\$ Commented Nov 8, 2011 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\$ Commented Nov 8, 2011 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
    Commented Nov 9, 2011 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\$ Commented Nov 9, 2011 at 14:44
  • \$\begingroup\$ Answer to this question is the same as for gamedev.stackexchange.com/questions/19906/…. \$\endgroup\$
    – Dracontis
    Commented Jan 3, 2012 at 16:32

2 Answers 2

1
\$\begingroup\$

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.

\$\endgroup\$
1
  • \$\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
    Commented Dec 9, 2011 at 15:24
0
\$\begingroup\$

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.

\$\endgroup\$
1
  • \$\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
    Commented Feb 9, 2012 at 19:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .