Setting mouse position without System.Windows.Forms

前端 未结 2 1839
再見小時候
再見小時候 2021-01-19 00:45

Is there a way to manipulate the mouse position without using System.Windows.Forms.Cursor? Something like interop maybe?

Reason for this is that we are using a speci

相关标签:
2条回答
  • 2021-01-19 01:07
    private void MoveCursor()
    {
       // Set the Current cursor, move the cursor's Position,
       // and set its clipping rectangle to the form. 
    
       this.Cursor = new Cursor(Cursor.Current.Handle);
       Cursor.Position = new Point(Cursor.Position.X - 50, Cursor.Position.Y - 50);
       Cursor.Clip = new Rectangle(this.Location, this.Size);
    }
    
    0 讨论(0)
  • 2021-01-19 01:12

    oops my bad, read question too fast, heres the correct PInvoke call

    [DllImport("user32.dll")]
    static extern bool SetCursorPos(int X, int Y);
    

    Source: http://www.pinvoke.net/default.aspx/user32.setcursorpos

    0 讨论(0)
提交回复
热议问题