tags:

views:

487

answers:

4

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  A: 

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.

Wolf5
+ for "Move your real mouse outside the vm"
thijs
I've already tried using the Win32 api, had no success
Kirschstein
A: 

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.

thijs
A: 

Try this nifty little library, perhaps it will help you.

http://www.codeproject.com/KB/system/globalmousekeyboardlib.aspx

Chris

Chris Dunaway
A: 

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.

Kirschstein
That was (part of) my answer..
thijs