Moving Mouse in Python on VM
Question: I am trying to move my mouse using this simple code.

    
    
    import win32api, win32con
    def click(x,y):
        win32api.SetCursorPos((x,y))
        win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,x,y,0,0)
        win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,x,y,0,0)
    click(10,10)
    

My machine is running MacOS, and I run a Virtual Machine on my computer with
windows 7. When I run this code on my Virtual Machine, it doesnt move the
actual mouse, but rather uses a "ghost mouse" to make the click. When I try to
use this code to make the mouse move on a windows desktop machine, you can see
the cursor moving (unlike on my VM).

Are there any ideas to making the actual mouse cursor move on my virtual
machine through python?

Thanks!


Answer: From what I can tell, I don't really believe it's possible. For all the VM
knows, the host doesn't really even exist (for the most part). One major thing
VMs do is sandbox the client from the host. (See
[security.SE](http://security.stackexchange.com/questions/9011/does-a-virtual-
machine-stop-malware-from-doing-harm)).

The other thing is, that would be a massive security issue. If I had access to
your machine from the VM, then I could ostensibly click through and install
malware.

Now for the catch: You probably can.

VMS can communicate to their host through the network, so if you had a server
listening on the host for the communication, and the host moves the cursor
after reading the comms, then yes. Note that this method requires explicitly
setting up the host to listen to the client. No method I am aware of allows
the VM to directly interact with the host without the host "listening".

