Setting mouse position without System.Windows.Forms

孤人 提交于 2019-12-01 17:33:02

问题


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 specialized .NET subset which can't include System.Windows.Forms.


回答1:


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




回答2:


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);
}


来源:https://stackoverflow.com/questions/11092784/setting-mouse-position-without-system-windows-forms

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!