def get_screen_with_mouse_index(): mouseLocation = NSEvent.mouseLocation() screens = NSScreen.screens() for i, screen in enumerate(screens): if NSMouseInRect(mouseLocation, screen.frame(), False): return i return 0
def mouseLocation(isTopCoordinates=True): if (isTopCoordinates): mLoc = getMouseLoc() return (mLoc.x, mLoc.y) else: mLoc = NSEvent.mouseLocation() return (mLoc.x, mLoc.y)
def mouseLocation(isTopCoordinates = True): if (isTopCoordinates): mLoc = getMouseLoc() return (mLoc.x,mLoc.y) else: mLoc = NSEvent.mouseLocation() return (mLoc.x,mLoc.y)
def mouseClickCallback(proxy, type_, event, refcon): global break_counter # Get mouse click event mouseEvent = NSEvent.mouseLocation() if mouseEvent is None: pass else: # Save coordinates and time of clicking when cmd+r has been pressed if cmd_first == False: x = mouseEvent.x y = mouseEvent.y time = datetime.datetime.now() dt = time - time_0 info = [time, x, y] event_list.append(info) if ROIx_min <= x <= ROIx_max and ROIy_min <= y <= ROIy_max: # Save second copy of clicks within ROI event_ROI.append(info) print('ROI', info) elif YESx_min <= x <= YESx_max and YESy_min <= y <= YESy_max: event_YES.append(info) print('YES', info) elif NOx_min <= x <= NOx_max and NOy_min <= y <= NOy_max: event_NO.append(info) print('NO', info) break_counter = 0
def cursor_position(): """Get the current mouse position. Returns: Tuple of the x and y coordinates of the mouse cursor. """ d = NSEvent.mouseLocation() return (d.x, d.y)
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"
def location(self): loc = NSEvent.mouseLocation() return loc.x, Quartz.CGDisplayPixelsHigh(0) - loc.y
def position(): loc = NSEvent.mouseLocation() return loc.x, CGDisplayPixelsHigh(0) - loc.y
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)
def getPosition(self): loc = NSEvent.mouseLocation() return (loc.x, CGDisplayPixelsHigh(0) - loc.y)
def _position_get(self): pos = NSEvent.mouseLocation() return pos.x, Quartz.CGDisplayPixelsHigh(0) - pos.y
def position(self): location = NSEvent.mouseLocation() return int(location.x), int(CG.CGDisplayPixelsHigh(0) - location.y)
def get_cursor_pos(): d = NSEvent.mouseLocation() return (d.x, d.y)
def position(self): loc = NSEvent.mouseLocation() return loc.x, Quartz.CGDisplayPixelsHigh(0) - loc.y
def position(): loc = NSEvent.mouseLocation() return Point(loc.x, CGDisplayPixelsHigh(0) - loc.y)