问题
I'm writing a toy application that plays with the mouse cursor, and I'm trying to move it programmticly. Using either Cursor.Position = ...
or Win32 interop calls work fine on a normal machine, but I'm having difficulties getting it to work under VMWare.
Does anyone have any suggestions?
EDIT
To clarify:
I've got a small windows forms application I've made running inside the VM, it has one button on it, when clicked it is supposed to move the mouse cursor inside the VM. I've used both the Cursor.Position method and the approach that Wolf5 has suggested.
回答1:
Try this instead:
[DllImport("user32", SetLastError = true)]
private static extern int SetCursorPos(int x, int y);
public static void SetMousePos(Point p) {
SetMousePos(p.X, p.Y);
}
public static void SetMousePos(int x, int y) {
SetCursorPos(x, y);
}
Of course you will have to make sure VMWARE has focus in the first place since it cannot set the mouse position of your mouse outside VMWARE.
回答2:
Don't focus the VM with your real mouse. Or uninstall the VMWare mouse driver so the VM doesn't get the focus unless you click inside it.
回答3:
I have resolved the issue.
In a desperate attempt to try anything i finally gave up and un-installed the mouse driver from the VM. After a reboot, my toy application works.
The device was listed as a VMWare Pointing device, after the reboot it's coming up as an "unknown device", but the mouse still works. Albeit I a little on the nippy side.
来源:https://stackoverflow.com/questions/969031/programaticly-move-mouse-in-vmware-c-sharp