我有一个带坐标的二维数组,我想让鼠标移动到那些坐标在WPF应用程序中创建的特定模式.你能帮助我吗?我已经尝试过Cursor类但它不起作用.显然我做错了什么.
private void SetPosition( int a, int b)
{
this.Cursor = new Cursor(Cursor.Current.Handle);
Cursor.Position = new Point(a, b);
}
Run Code Online (Sandbox Code Playgroud)
这是我使用a和b来自数组的方法.提前致谢!
PS该方法是在每秒触发20次的事件中.
vcs*_*nes 11
我不完全确定在WPF中是否有更好的方法(看起来你使用的代码是针对WinForms的),但使用Platform Invoke SetCursorPos似乎可以解决这个问题:
private void SetPosition(int a, int b)
{
SetCursorPos(a, b);
}
[DllImport("User32.dll")]
private static extern bool SetCursorPos(int X, int Y);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13957 次 |
| 最近记录: |