我正在为WPF应用程序使用Teststack白色框架(C#、. net)编写一些自动化测试。我希望在运行测试时冻结任何光标移动。有什么办法吗?
我已经尝试过
public partial class NativeMethods
{
[DllImport("user32.dll", SetLastError = true)]
public static extern bool BlockInput(bool fBlockIt);
}
但由于我的应用程序未以管理员权限运行而无法正常工作
我尝试过 NativeMethods.BlockInput(true);
我收到访问被拒绝的异常
答案 0 :(得分:0)
我认为您可以使用ClipCursor
[DllImport("user32.dll")]
static extern void ClipCursor(ref System.Drawing.Rectangle rect);
[DllImport("user32.dll")]
static extern void ClipCursor(IntPtr rect);
public MainWindow()
{
InitializeComponent();
this.DataContext = this;
this.Loaded += MainWindow_Loaded;
this.MouseMove += Window_MouseMove;
}
void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
this.WindowState = WindowState.Maximized;
HideMouse();
}
private void Window_MouseMove(object sender, MouseEventArgs e)
{
HideMouse();
}
private void HideMouse()
{
System.Drawing.Rectangle r = new System.Drawing.Rectangle(0, 0, 0, 0);
ClipCursor(ref r);
}