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 ?

2
  • If you're interested in a C++ method for Windows, SendInput Commented Jul 18, 2012 at 4:34
  • Are you monitoring a port as such or are you only interested in the actual click event? Commented Jul 18, 2012 at 4:44

1 Answer 1

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);
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.