Search code examples
c#winformsmousevirtualmouseclick-event

Simulate mouse events


I'm trying to simulate a mouse move using the following code: mouse_event(MOUSEEVENTF_MOVE,150 ,150, 0, 0);

It works fine, but the X and Y coordinates start from my current cursor position. Is there a way I can make them start at the upper left of my screen?

I'm working in a Windows form app using c#

If you have no clue of what I'm asking, I tried to draw it for you;enter image description here


Solution

  • The MSDN documents say that you can simply set the position of a form's cursor. Just do that, then send your mouseevent.

    System.Windows.Forms.Cursor.Position = new Point(0, 0);
    

    followed by your mouse_event, should do the trick.