Possible Duplicate:
Getting mouse position in c#
Is it possible to mimic a peripheral , say , a mouse on one of the ports and write a program that could send a click to an (x,y) on the display ?
Possible Duplicate:
Getting mouse position in c#
Is it possible to mimic a peripheral , say , a mouse on one of the ports and write a program that could send a click to an (x,y) on the display ?
Yes you can. I did a MouseController for NUnitForms years ago. Check out http://nunitforms.sourceforge.net/
The source code of the mouse controller is at http://nunitforms.svn.sourceforge.net/viewvc/nunitforms/trunk/nunitforms/source/NUnitForms/MouseController.cs?revision=32&view=markup
The key is using the Win32 function SendInput; http://msdn.microsoft.com/en-us/library/windows/desktop/ms646310(v=vs.85).aspx
The SendInput function takes a union as input, which is not easily supported by C#. What I have done is to define two functions SendMouseInput and SendKeyboardInput that specify different input structs but call the same function.
[DllImport("user32.dll", EntryPoint="SendInput", SetLastError=true)]
internal static extern int SendMouseInput(int cInputs, ref MOUSEINPUT pInputs, int cbSize);
[DllImport("user32.dll", EntryPoint="SendInput", SetLastError=true)]
internal static extern int SendKeyboardInput(int cInputs, ref KEYBDINPUT pInputs, int cbSize);