Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Control the mouse cursor using C#

I'm trying to write a program using C# that would allow me to remotely take control of the mouse on a windows machine. This would allow me to issue commands to the mouse to move to a certain part of the screen and then click on that part of the screen.

I was wondering if there were any C# classes that I would be useful in achieving this goal.

Any help is appreciated. Thanks!

like image 673
scorpio Avatar asked Nov 02 '10 22:11

scorpio


2 Answers

I think unless you're just positioning the cursor over your own application, you have to use a windows api call. You can reference that in C# as such:

[DllImport("user32")]
public static extern int SetCursorPos(int x, int y);

There's source code for a more complete Win32 wrapper class here

like image 161
Kevin Stricker Avatar answered Oct 11 '22 14:10

Kevin Stricker


You will have to write a client application that us run on the remote machine to receive your mouse movement command messages. That client application will then take control of the mouse, and move it to commanded coordinates.

There are several applications that allow remote desktop control. Microsoft supplies at least a couple (Netmeeting, Remote Desktops). VNC is another popular tool. Joel has his CoPilot built on VNC.

like image 20
aaaa bbbb Avatar answered Oct 11 '22 14:10

aaaa bbbb