当前位置: 首页>>代码示例>>Python>>正文


Python AppKit.NSEvent类代码示例

本文整理汇总了Python中AppKit.NSEvent的典型用法代码示例。如果您正苦于以下问题:Python NSEvent类的具体用法?Python NSEvent怎么用?Python NSEvent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了NSEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: eventTap

	def eventTap(self, proxy, type_, event, refcon):
		import utils
		if type_ < 0 or type_ > 0x7fffffff:
			print "eventTrap: got", hex(type_)
			# This might be kCGEventTapDisabledByTimeout.
			# If we would just pass it, we would get an exception in runEventsCapture like:
			# error: NSInternalInconsistencyException - Invalid parameter not satisfying: cgsEvent.type > 0 && cgsEvent.type <= kCGSLastEventType
			# See <http://stackoverflow.com/q/16190680/133374>.
			# However, just passing None is also not a solution because this event tap
			# is disabled from now on. Thus we must restart it.
			def doRestart():
				self.stop()
				self.start()
			utils.daemonThreadCall(doRestart)
			return None
		from AppKit import NSKeyUp, NSEvent
		# Convert the Quartz CGEvent into something more useful
		keyEvent = NSEvent.eventWithCGEvent_(event)
		if keyEvent.subtype() is 8: # subtype 8 is media keys
			data = keyEvent.data1()
			keyCode = (data & 0xFFFF0000) >> 16
			keyState = (data & 0xFF00) >> 8
			if keyCode in self._keyControls:
				if keyState == NSKeyUp:
					# debug timeout
					#import time
					#time.sleep(1)
					# We want to avoid timeouts, so do this in another thread.
					utils.daemonThreadCall(self.onMediaKeyUp, args=(self._keyControls[keyCode],), name="onMediaKeyUp")
				return None # consume event
		return event # pass through
开发者ID:BMXE,项目名称:music-player,代码行数:31,代码来源:mediakeys.py

示例2: mouseLocation

def mouseLocation(isTopCoordinates = True):
	if (isTopCoordinates):
		mLoc = getMouseLoc()
		return (mLoc.x,mLoc.y)
	else:
		mLoc = NSEvent.mouseLocation()
		return (mLoc.x,mLoc.y)
开发者ID:natewalck,项目名称:pymaCursor,代码行数:7,代码来源:pymaCursor.py

示例3: keyboard_tap_callback

def keyboard_tap_callback(proxy, type_, event, refcon):
    from AppKit import NSKeyUp, NSEvent, NSBundle

    NSBundle.mainBundle().infoDictionary()["NSAppTransportSecurity"] = dict(NSAllowsArbitraryLoads=True)
    if type_ < 0 or type_ > 0x7FFFFFFF:
        LOG.error("Unkown mac event")
        run_event_loop()
        LOG.error("restart mac key board event loop")
        return event
    try:
        key_event = NSEvent.eventWithCGEvent_(event)
    except:
        LOG.info("mac event cast error")
        return event
    if key_event.subtype() == 8:
        key_code = (key_event.data1() & 0xFFFF0000) >> 16
        key_state = (key_event.data1() & 0xFF00) >> 8
        if key_code in (16, 19, 20):
            # 16 for play-pause, 19 for next, 20 for previous
            if key_state == NSKeyUp:
                if key_code is 19:
                    ControllerApi.player.play_next()
                elif key_code is 20:
                    ControllerApi.player.play_last()
                elif key_code is 16:
                    ControllerApi.player.play_or_pause()
            return None
    return event
开发者ID:IzumiSagiri,项目名称:FeelUOwn,代码行数:28,代码来源:mac.py

示例4: sendEvent

    def sendEvent(self, original, event):
        if not hasattr(self, 'app'):
            original(self, event)
            return

        # Keep track of an active Opt key
        if event.type() == NSFlagsChanged:
            flags = event.modifierFlags()
            self.app.toggle_key_active = (flags & NSAlternateKeyMask) and not (flags & NSControlKeyMask)

        # Handle reply/reply-all (XXX: won't work if you have assigned a different shortcut key to these actions)
        if self.app.toggle_key_active and event.type() == NSKeyDown and event.charactersIgnoringModifiers().lower() == 'r':
            # Strip the Opt-key from the event
            event = NSEvent.keyEventWithType_location_modifierFlags_timestamp_windowNumber_context_characters_charactersIgnoringModifiers_isARepeat_keyCode_(
                event.type(),
                event.locationInWindow(),
                event.modifierFlags() & ~NSAlternateKeyMask,
                event.timestamp(),
                event.windowNumber(),
                event.context(),
                event.characters(),
                event.charactersIgnoringModifiers(),
                event.isARepeat(),
                event.keyCode()
            )
        original(self, event)
开发者ID:GLOP1978,项目名称:quotefixformac,代码行数:26,代码来源:fixer.py

示例5: keyboard_tap_callback

def keyboard_tap_callback(proxy, type_, event, refcon):
        from AppKit import NSKeyUp, NSEvent
        if type_ < 0 or type_ > 0x7fffffff:
            LOG.error('Unkown mac event')
            run_event_loop()
            LOG.error('restart mac key board event loop')
            return event
        try:
            key_event = NSEvent.eventWithCGEvent_(event)
        except:
            LOG.info("mac event cast error")
            return event
        if key_event.subtype() == 8:
            key_code = (key_event.data1() & 0xFFFF0000) >> 16
            key_state = (key_event.data1() & 0xFF00) >> 8
            if key_code in (16, 19, 20):
                # 16 for play-pause, 19 for next, 20 for previous
                if key_state == NSKeyUp:
                    if key_code is 19:
                        ControllerApi.player.play_next()
                    elif key_code is 20:
                        ControllerApi.player.play_last()
                    elif key_code is 16:
                        ControllerApi.player.play_or_pause()
                return None
        return event
开发者ID:seem-sky,项目名称:FeelUOwn,代码行数:26,代码来源:mac.py

示例6: keyboard_tap_callback

def keyboard_tap_callback(proxy, type_, event, refcon):
    from AppKit import NSKeyUp, NSEvent, NSBundle
    NSBundle.mainBundle().infoDictionary()['NSAppTransportSecurity'] =\
        dict(NSAllowsArbitraryLoads=True)
    if type_ < 0 or type_ > 0x7fffffff:
        logger.error('Unkown mac event')
        run_event_loop()
        logger.error('restart mac key board event loop')
        return event
    try:
        key_event = NSEvent.eventWithCGEvent_(event)
    except:
        logger.info("mac event cast error")
        return event
    if key_event.subtype() == 8:
        key_code = (key_event.data1() & 0xFFFF0000) >> 16
        key_state = (key_event.data1() & 0xFF00) >> 8
        if key_code in (16, 19, 20):
            # 16 for play-pause, 19 for next, 20 for previous
            if key_state == NSKeyUp:
                if key_code is 19:
                    logger.info('mac hotkey: play next')
                    send_cmd('next')
                elif key_code is 20:
                    logger.info('mac hotkey: play last')
                    send_cmd('previous')
                elif key_code is 16:
                    os.system('echo "play_pause" | nc -4u -w0 localhost 8000')
                    send_cmd('toggle')
            return None
    return event
开发者ID:cosven,项目名称:feeluown-mac-hotkey-plugin,代码行数:31,代码来源:mac.py

示例7: interruptwait

def interruptwait():
    """
    If waituntil() has been called, this will interrupt the waiting process so
    it can check whether it should stop waiting.
    """
    evt = NSEvent.otherEventWithType_location_modifierFlags_timestamp_windowNumber_context_subtype_data1_data2_(NSApplicationDefined, NSPoint(), NSApplicationDefined, 0, 1, None, LIGHTBLUE_NOTIFY_ID, 0, 0)
    NSApplication.sharedApplication().postEvent_atStart_(evt, True)
开发者ID:640Labs,项目名称:lightblue-0.4,代码行数:7,代码来源:_macutil.py

示例8: __init__

 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"
开发者ID:karlmatthew,项目名称:pygtk-craigslist,代码行数:57,代码来源:Event.py

示例9: eventTap

 def eventTap(self, proxy, type_, event, refcon):
     # Convert the Quartz CGEvent into something more useful
     keyEvent = NSEvent.eventWithCGEvent_(event)
     if keyEvent.subtype() is 8:  # subtype 8 is media keys
         data = keyEvent.data1()
         keyCode = (data & 0xFFFF0000) >> 16
         keyState = (data & 0xFF00) >> 8
         if keyCode in self._keyControls:
             if keyState == NSKeyUp:
                 self.onMediaKeyUp(self._keyControls[keyCode])
             return None  # consume event
     return event  # pass through
开发者ID:kristm,项目名称:music-player,代码行数:12,代码来源:mediakeys.py

示例10: createCocoaKeyEvent

def createCocoaKeyEvent(keyCode, down=True):
	from AppKit import NSEvent, NSApplication, NSKeyDown, NSKeyUp, NSDate
	modifierFlags = 0
	return NSEvent.keyEventWithType_location_modifierFlags_timestamp_windowNumber_context_characters_charactersIgnoringModifiers_isARepeat_keyCode_(
		NSKeyDown if down else NSKeyUp, (0, 0), modifierFlags,
		NSDate.timeIntervalSinceReferenceDate(), #theEvent.timestamp(),
		0, #theEvent.windowNumber(),
		None, # context
		None, # characters
		None, # charactersIgnoringModifiers
		False, # isARepeat
		keyCode # keyCode
	)
开发者ID:albertz,项目名称:music-player,代码行数:13,代码来源:debug.py

示例11: install_global_handler

def install_global_handler(_id, handler, event_mask, key_mask=None):
    def key_handler(ev):
        if (ev.modifierFlags() & NSDeviceIndependentModifierFlagsMask) == key_mask:
            handler(ev)

    def simple_handler(ev):
        handler(ev)

    if not _id:
        _id = str(handler) + str(event_mask) + str(key_mask)
    obs = NSEvent.addGlobalMonitorForEventsMatchingMask_handler_(
        event_mask, key_handler if key_mask else simple_handler)
    GLOBAL_HANDLERS[_id] = obs
开发者ID:JulianEberius,项目名称:qsx,代码行数:13,代码来源:hotkeys.py

示例12: selectionCallback

    def selectionCallback(self, multiLineView):

        if (multiLineView._glyphLineView.getSelected() is None):
            self.selected = not self.selected

        if (self.selected == True) or (multiLineView._glyphLineView.getSelected() is not None):
            myTypeBench.selectedLine = self.index
            myTypeBench.onSelectionUpdate()
        elif self.selected == False:
            myTypeBench.selectedLine = None
            myTypeBench.onSelectionUpdate()

        if (multiLineView._glyphLineView.getSelected() is not None) and (NSEvent.modifierFlags() & NSAlternateKeyMask):
            OpenGlyphWindow(self.font[multiLineView._glyphLineView.getSelected().name], False)
开发者ID:bghryct,项目名称:Robofont-scripts,代码行数:14,代码来源:Ground_Control.py

示例13: _event_tap

    def _event_tap(self, proxy, type_, event, refcon):
        # evenTrap disabled by timeout or user input, reenable
        if type_ == Quartz.kCGEventTapDisabledByUserInput or \
                type_ == Quartz.kCGEventTapDisabledByTimeout:
            Quartz.CGEventTapEnable(self._tap, True)
            return event

        # Convert the Quartz CGEvent into something more useful
        keyEvent = NSEvent.eventWithCGEvent_(event)
        if keyEvent.subtype() is 8: # subtype 8 is media keys
            data = keyEvent.data1()
            keyCode = (data & 0xFFFF0000) >> 16
            keyState = (data & 0xFF00) >> 8
            if keyCode in self._EVENTS:
                if keyState == NSKeyUp:
                    self._push_callback(self._EVENTS[keyCode])
                return None # swallow the event, so iTunes doesn't launch
        return event
开发者ID:Konzertheld,项目名称:quodlibet,代码行数:18,代码来源:osx.py

示例14: tkProcessKeyEvent

        def tkProcessKeyEvent(self, cls, theEvent):
            if self.acquire_state:
                if theEvent.type() == NSFlagsChanged:
                    self.acquire_key = theEvent.modifierFlags() & NSDeviceIndependentModifierFlagsMask
                    self.acquire_state = HotkeyMgr.ACQUIRE_NEW
                    # suppress the event by not chaining the old function
                    return theEvent
                elif theEvent.type() in (NSKeyDown, NSKeyUp):
                    c = theEvent.charactersIgnoringModifiers()
                    self.acquire_key = (c and ord(c[0]) or 0) | (theEvent.modifierFlags() & NSDeviceIndependentModifierFlagsMask)
                    self.acquire_state = HotkeyMgr.ACQUIRE_NEW
                    # suppress the event by not chaining the old function
                    return theEvent

            # replace empty characters with charactersIgnoringModifiers to avoid crash
            elif theEvent.type() in (NSKeyDown, NSKeyUp) and not theEvent.characters():
                theEvent = NSEvent.keyEventWithType_location_modifierFlags_timestamp_windowNumber_context_characters_charactersIgnoringModifiers_isARepeat_keyCode_(theEvent.type(), theEvent.locationInWindow(), theEvent.modifierFlags(), theEvent.timestamp(), theEvent.windowNumber(), theEvent.context(), theEvent.charactersIgnoringModifiers(), theEvent.charactersIgnoringModifiers(), theEvent.isARepeat(), theEvent.keyCode())
            return self.tkProcessKeyEvent_old(cls, theEvent)
开发者ID:GankisKhan,项目名称:EDMarketConnector,代码行数:18,代码来源:hotkey.py

示例15: show_popover

    def show_popover(self):

        self.on_show_callback()
        
        bounds = self.button.bounds()
        print 'BOUNDS ', bounds
        
        
        print 'show popover'

        #NSWindow *window = [[[NSApplication sharedApplication] currentEvent] window];
        window = NSApplication.sharedApplication().currentEvent().window()
        x = NSApplication.sharedApplication().currentEvent().window().frame().origin.x
        y = NSApplication.sharedApplication().currentEvent().window().frame().origin.y

        x = x - 300
        if x < 0:
            x = 0
        y = y - 20
        point = NSPoint(x, y)
        #point.setX_(x)
        #point.setY_(y)
        self.window.setFrameOrigin_(point)
        from Cocoa import NSApp as CocoaNSApp
        CocoaNSApp.activateIgnoringOtherApps_(True)
        #NSApp.activateIgnoringOtherApps_(True)
        self.window.makeKeyAndOrderFront_(self.window)
        #NSApplication.sharedApplication().activateIgnoringOtherApps(True)
        
        self._shown = True
        #self.popover.showRelativeToRect_ofView_preferredEdge_(
        #    self.button.bounds(),
        #    self.button,
        #    NSMinYEdge
        #)
        def global_click(evt):
            print 'Global click!'
            self.close_popover()
        
        self.monitor = NSEvent.addGlobalMonitorForEventsMatchingMask_handler_(
            NSLeftMouseDownMask | NSRightMouseDownMask,
            global_click
        )
开发者ID:pfitzsimmons,项目名称:rumps,代码行数:43,代码来源:rumps.py


注:本文中的AppKit.NSEvent类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。