Send keyboard and mouse events to DirectX application in C#?

Vercas picture Vercas · May 11, 2011 · Viewed 7.3k times · Source

I need to send global keystrokes and mouse events to another application, which is coincidentally using using DirectX. (No controls/handles other than the window itself)
For example, I need to hold key X for 2 seconds and then release it...
I need to push Right Click down on coordinates x:600 and y:350, move the mouse 100 pixels down and then release the Right Click.
I also need to push 2 or more keys at once, like X and Y, and stop X after 2 seconds and Y after 2 more seconds.
So basically I would need full control of the input system...
It would also be ideal if I could control the application while maximized or in background. (optionally)

For the skeptics... The teacher made a DirectX application for drawing for our school. I am asked to make an application that draws samples on it, like a train or flower or something... I will be reading images and use the input to set the color and click on the canvas...

Answer

vineetv2821993 picture vineetv2821993 · Apr 10, 2014

If you want to use a library for C# that will make your work easier then read following link -

http://www.codeproject.com/Articles/117657/InputManager-library-Track-user-input-and-simulate

Other than .Net C# you can use other language alternative like in Java where, there is no confusion of direct x or normal input -

http://docs.oracle.com/javase/7/docs/api/java/awt/Robot.html