请尝试this page处的代码。它定义了两个函数mousemove和mouseclick,这两个函数连接到了苹果在Python和平台的Quartz库之间的集成中。
这段代码在10.6上运行,我在10.7上使用它。这段代码的好处是它生成鼠标事件,而有些解决方案没有。我用它来控制BBC I player,方法是将鼠标事件发送到Flash播放器中的已知按钮位置(我知道它非常脆弱)。尤其需要鼠标移动事件,否则Flash播放器永远不会隐藏鼠标光标。像CGWarpMouseCursorPosition这样的函数不会这样做。from Quartz.CoreGraphics import CGEventCreateMouseEvent
from Quartz.CoreGraphics import CGEventPost
from Quartz.CoreGraphics import kCGEventMouseMoved
from Quartz.CoreGraphics import kCGEventLeftMouseDown
from Quartz.CoreGraphics import kCGEventLeftMouseDown
from Quartz.CoreGraphics import kCGEventLeftMouseUp
from Quartz.CoreGraphics import kCGMouseButtonLeft
from Quartz.CoreGraphics import kCGHIDEventTap
def mouseEvent(type, posx, posy):
theEvent = CGEventCreateMouseEvent(
None,
type,
(posx,posy),
kCGMouseButtonLeft)
CGEventP