简体   繁体   English

在 Windows 10 中设置 Cursor.Position 无效

[英]Setting Cursor.Position in Windows 10 not working

I want to set the mouse cursor to a certain position by using:我想通过以下方式将鼠标 cursor 设置为某个 position:

Cursor.Position = new Point(Int32.Parse(X), Int32.Parse(Y));

This works normally in Windows 7, but not in Windows 10. The cursor is not moving, but when the position is on a button you can see the hover reaction.这在 Windows 7 中正常工作,但在 Windows 10 中不起作用。cursor 没有移动,但是当 position 在按钮上时,您可以看到 hover 的反应。

Is this a known issue?这是一个已知的问题? If yes, is there a workaround for this?如果是,是否有解决方法?

Thanks in advance提前致谢

EDIT 1: This seems to be a visual problem meaning only the visible cursor does not move.编辑 1:这似乎是一个视觉问题,意味着只有可见的 cursor 不会移动。 For test purposes I have created a button (button_1) which performs above code on a click.出于测试目的,我创建了一个按钮 (button_1),它在单击时执行上述代码。 I set the X and Y coordinates to be on another button (button_2).我将 X 和 Y 坐标设置在另一个按钮 (button_2) 上。 Now when I click button_1 button_2 gets highlighted as if the cursor is hovering on it.现在,当我单击 button_1 时,button_2 会突出显示,就好像 cursor 悬停在上面一样。 If I click button_1 again without moving the mouse, button_2 gets clicked.如果我在不移动鼠标的情况下再次单击 button_1,则会单击 button_2。 When I move the mouse between the clicks button_2 is not highlighted anymore.当我在点击之间移动鼠标时,button_2 不再突出显示。 Thus, resulting in the second click doing the same as the first.因此,导致第二次点击与第一次点击相同。

EDIT 2 I tried using the following function instead of Cursor.Position , but with the same result.编辑 2我尝试使用以下 function 而不是Cursor.Position ,但结果相同。

[DllImport("User32.Dll")]
public static extern long SetCursorPos(int x, int y);

Ok so this is not a Windows 10 problem. 好的,这不是Windows 10问题。 I did not realize that this issue could have something to do with the fact that I was working in a VM. 我没有意识到这个问题可能与我在VM中工作有关。 Consider this as solved. 认为这已解决。

One thing I noticed is that you need to execute the program as a system administrator if the external application also requires to run as a system administrator.我注意到的一件事是,如果外部应用程序也需要以系统管理员身份运行,则您需要以系统管理员身份执行该程序。 Otherwise, Cursor doesn't work on the external application.否则,Cursor 在外部应用程序上不起作用。 This issue occurs in Windows 10 but not in Windows 7.此问题出现在 Windows 10 中,但不出现在 Windows 7 中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM