0

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 ?

Community
  • 1
  • 1
Kasisnu
  • 239
  • 5
  • 16
  • If you're interested in a C++ method for Windows, [`SendInput`](http://msdn.microsoft.com/en-us/library/windows/desktop/ms646310(v=vs.85).aspx) – chris Jul 18 '12 at 04:34
  • Are you monitoring a port as such or are you only interested in the actual click event? – Eben Roux Jul 18 '12 at 04:44

1 Answers1

0

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);
Richard Schneider
  • 34,944
  • 9
  • 57
  • 73