def set_mouse_position(self, x, y, absolute=False):
if absolute:
# If absolute, then x, y is given in global display coordinates
# which sets (0,0) at top left corner of main display. It is possible
# to warp the mouse position to a point inside of another display.
quartz.CGWarpMouseCursorPosition(CGPoint(x,y))
else:
# Window-relative coordinates: (x, y) are given in window coords
# with (0,0) at bottom-left corner of window and y up. We find
# which display the window is in and then convert x, y into local
# display coords where (0,0) is now top-left of display and y down.
screenInfo = self._nswindow.screen().deviceDescription()
displayID = screenInfo.objectForKey_(get_NSString('NSScreenNumber'))
displayID = displayID.intValue()
displayBounds = quartz.CGDisplayBounds(displayID)
frame = self._nswindow.frame()
windowOrigin = frame.origin
x += windowOrigin.x
y = displayBounds.size.height - windowOrigin.y - y
quartz.CGDisplayMoveCursorToPoint(displayID, NSPoint(x,y))
评论列表
文章目录