简体   繁体   中英

Setting Cursor.Position in Windows 10 not working

I want to set the mouse cursor to a certain position by using:

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.

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. For test purposes I have created a button (button_1) which performs above code on a click. I set the X and Y coordinates to be on another button (button_2). Now when I click button_1 button_2 gets highlighted as if the cursor is hovering on it. If I click button_1 again without moving the mouse, button_2 gets clicked. When I move the mouse between the clicks button_2 is not highlighted anymore. 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.

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

Ok so this is not a Windows 10 problem. I did not realize that this issue could have something to do with the fact that I was working in a 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. This issue occurs in Windows 10 but not in Windows 7.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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