本文整理汇总了Python中AppKit.NSEvent.mouseLocation方法的典型用法代码示例。如果您正苦于以下问题:Python NSEvent.mouseLocation方法的具体用法?Python NSEvent.mouseLocation怎么用?Python NSEvent.mouseLocation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AppKit.NSEvent
的用法示例。
在下文中一共展示了NSEvent.mouseLocation方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: mouseLocation
# 需要导入模块: from AppKit import NSEvent [as 别名]
# 或者: from AppKit.NSEvent import mouseLocation [as 别名]
def mouseLocation(isTopCoordinates = True):
if (isTopCoordinates):
mLoc = getMouseLoc()
return (mLoc.x,mLoc.y)
else:
mLoc = NSEvent.mouseLocation()
return (mLoc.x,mLoc.y)
示例2: __init__
# 需要导入模块: from AppKit import NSEvent [as 别名]
# 或者: from AppKit.NSEvent import mouseLocation [as 别名]
def __init__(self, ns_event):
self._ns_event = ns_event
_ns_type = ns_event.type()
kind = _ns_event_type_to_kind[_ns_type]
self.kind = kind
self.time = ns_event.timestamp()
ns_window = ns_event.window()
is_mouse_event = kind in _mouse_events
if is_mouse_event:
ns_win_pos = ns_event.locationInWindow()
x, y = ns_window.convertBaseToScreen_(ns_win_pos)
else:
ns_last_mouse = Globals.ns_last_mouse_moved_event
if ns_last_mouse:
ns_window = ns_last_mouse.window()
if ns_window:
ns_win_pos = ns_last_mouse.locationInWindow()
x, y = ns_window.convertBaseToScreen_(ns_win_pos)
else:
x, y = ns_last_mouse.locationInWindow()
else:
x, y = NSEvent.mouseLocation()
h = Globals.ns_screen_height
self.global_position = (x, h - y)
if is_mouse_event:
self.button = _ns_event_type_to_button.get(_ns_type, '')
if kind == 'mouse_down':
self.num_clicks = ns_event.clickCount()
self.delta = (ns_event.deltaX(), ns_event.deltaY())
ns_flags = ns_event.modifierFlags()
self.shift = self.extend_contig = (ns_flags & NSShiftKeyMask) <> 0
self.control = (ns_flags & NSControlKeyMask) <> 0
self.command = self.extend_noncontig = (ns_flags & NSCommandKeyMask) <> 0
self.option = (ns_flags & NSAlternateKeyMask) <> 0
if kind in _key_events:
self.auto = ns_event.isARepeat()
ns_chars = ns_event.characters()
#print "Event.__init__: ns_chars =", repr(ns_chars) ###
self.unichars = ns_chars
if len(ns_chars) == 1:
if ns_chars == "\x19" and ns_event.keyCode() == 48:
self.char = "\t"
elif ns_chars == "\x7f":
self.char = "\x08"
elif ns_chars <= "\x7e":
self.char = str(ns_chars)
#else:
# self.char = ns_chars
ns_unmod = ns_event.charactersIgnoringModifiers()
key = _ns_keycode_to_keyname.get(ns_chars, '')
if not key and u"\x20" <= ns_unmod <= u"\x7e":
key = str(ns_unmod)
self.key = key
if key == 'enter':
self.char = "\r"
elif key == 'delete':
self.char = "\x7f"
示例3: position
# 需要导入模块: from AppKit import NSEvent [as 别名]
# 或者: from AppKit.NSEvent import mouseLocation [as 别名]
def position(self):
loc = NSEvent.mouseLocation()
return loc.x, Quartz.CGDisplayPixelsHigh(0) - loc.y
示例4: getPosition
# 需要导入模块: from AppKit import NSEvent [as 别名]
# 或者: from AppKit.NSEvent import mouseLocation [as 别名]
def getPosition(self):
loc = NSEvent.mouseLocation()
return (loc.x, CGDisplayPixelsHigh(0) - loc.y)
示例5: _position_get
# 需要导入模块: from AppKit import NSEvent [as 别名]
# 或者: from AppKit.NSEvent import mouseLocation [as 别名]
def _position_get(self):
pos = NSEvent.mouseLocation()
return pos.x, Quartz.CGDisplayPixelsHigh(0) - pos.y
示例6: CGWindowListCopyWindowInfo
# 需要导入模块: from AppKit import NSEvent [as 别名]
# 或者: from AppKit.NSEvent import mouseLocation [as 别名]
else:
pid = None
while 1:
app = NSWorkspace.sharedWorkspace().activeApplication()
if pid != app['NSApplicationProcessIdentifier']:
pid = app['NSApplicationProcessIdentifier']
winList = CGWindowListCopyWindowInfo(kCGWindowListOptionOnScreenOnly,
kCGNullWindowID)
activeWin = None
for win in winList:
# print 'win:', win
if win['kCGWindowOwnerPID'] == pid and \
win['kCGWindowAlpha'] != 0 and win['kCGWindowLayer'] == 0:
print win
activeWin = win
break
if activeWin:
bounds = activeWin['kCGWindowBounds']
loc = NSEvent.mouseLocation()
loc.y = 1080 - loc.y # this might need to be tweaked depending on layout of displays
print (app['NSApplicationName'], bounds['X'], bounds['Y'], bounds['Width'], bounds['Height']), (loc.x, loc.y)
if loc.x < bounds['X'] or loc.x >= bounds['X'] + bounds['Width'] or \
loc.y < bounds['Y'] or loc.y >= bounds['Y'] + bounds['Height']:
x = bounds['X'] + bounds['Width']/2
y = bounds['Y'] + bounds['Height']/2
print 'move to', (x, y)
mousemove(x, y)
time.sleep(0.2)
示例7: position
# 需要导入模块: from AppKit import NSEvent [as 别名]
# 或者: from AppKit.NSEvent import mouseLocation [as 别名]
def position():
loc = NSEvent.mouseLocation()
return Point(loc.x, CGDisplayPixelsHigh(0) - loc.y)