简体   繁体   English

无法以编程方式在VirtualBox中移动鼠标光标

[英]Cannot programmatically move mouse cursor in VirtualBox

I'm trying to use this Python code: 我正在尝试使用以下Python代码:

import math
import win32api
for i in xrange(500):
    x = 500 + math.sin(math.pi * i / 100) * 500
    y = 500 + math.cos(i) * 100
    x, y = int(x), int(y)
    win32api.SetCursorPos((x, y))
    time.sleep(.01)

taken from here to move the mouse cursor in an XP VirtualBox. 此处移来在XP VirtualBox中移动鼠标光标。 The mouse icon will flicker to the appropriate graphic (when it hits the edge of a window it turns into the <-> resize image, for instance), but it doesn't actually move the visible cursor. 鼠标图标将闪烁到适当的图形(例如,当它碰到窗口的边缘时,它会变成<->调整大小的图像),但实际上并不会移动可见的光标。 I can move the mouse around while the code is running. 我可以在代码运行时四处移动鼠标。 Same result using the ctypes example in the above link. 使用上面链接中的ctypes示例获得相同的结果。 It works fine in the Win7 host. 它在Win7主机中正常工作。

I have Guest Additions installed, if that matters. 如果有的话,我已经安装了Guest Additions。

您好像忘记了导入win32api。

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

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