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


Python X.KeyPress方法代码示例

本文整理汇总了Python中Xlib.X.KeyPress方法的典型用法代码示例。如果您正苦于以下问题:Python X.KeyPress方法的具体用法?Python X.KeyPress怎么用?Python X.KeyPress使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Xlib.X的用法示例。


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

示例1: listen

# 需要导入模块: from Xlib import X [as 别名]
# 或者: from Xlib.X import KeyPress [as 别名]
def listen(self):
        self.grab()
        while True:
            evt = self.disp.next_event()
            if evt.type in [X.KeyPress, X.KeyRelease]:
                keycode = evt.detail
                keysym = self.disp.keycode_to_keysym(keycode, 0)
                char = XK.keysym_to_string(keysym)
                self.disp.allow_events(X.ReplayKeyboard, X.CurrentTime)

                self.mode(self, evt, char)

            if evt.type == X.DestroyNotify:
                if evt.window.id == self.id:
                    self.ungrab()
                    return 
开发者ID:gillescastel,项目名称:inkscape-shortcut-manager,代码行数:18,代码来源:main.py

示例2: normal_mode

# 需要导入模块: from Xlib import X [as 别名]
# 或者: from Xlib.X import KeyPress [as 别名]
def normal_mode(self, event, char):
    events.append(event)

    if event.type == X.KeyPress and char:
        pressed.add(event_to_string(self, event))
        return 

    if event.type != X.KeyRelease:
        return 

    handled = False
    if len(pressed) > 1:
        paste_style(self, pressed)
        handled = True
    elif len(pressed) == 1:
        # Get the only element in pressed
        ev = next(iter(pressed))
        handled = handle_single_key(self, ev)
        
    # replay events to Inkscape if we couldn't handle them
    if not handled:
        replay(self)

    events.clear()
    pressed.clear() 
开发者ID:gillescastel,项目名称:inkscape-shortcut-manager,代码行数:27,代码来源:normal.py

示例3: __init__

# 需要导入模块: from Xlib import X [as 别名]
# 或者: from Xlib.X import KeyPress [as 别名]
def __init__(self):
        threading.Thread.__init__(self)
        self.finished = threading.Event()
        
        # Give these some initial values
        self.mouse_position_x = 0
        self.mouse_position_y = 0
        self.ison = {"shift":False, "caps":False}
        
        # Compile our regex statements.
        self.isshift = re.compile('^Shift')
        self.iscaps = re.compile('^Caps_Lock')
        self.shiftablechar = re.compile('^[a-z0-9]$|^minus$|^equal$|^bracketleft$|^bracketright$|^semicolon$|^backslash$|^apostrophe$|^comma$|^period$|^slash$|^grave$')
        self.logrelease = re.compile('.*')
        self.isspace = re.compile('^space$')
        
        # Assign default function actions (do nothing).
        self.KeyDown = lambda x: True
        self.KeyUp = lambda x: True
        self.MouseAllButtonsDown = lambda x: True
        self.MouseAllButtonsUp = lambda x: True
        
        self.contextEventMask = [X.KeyPress,X.MotionNotify]
        
        # Hook to our display.
        self.local_dpy = display.Display()
        self.record_dpy = display.Display() 
开发者ID:OmkarPathak,项目名称:Python-Programs,代码行数:29,代码来源:pyxhook.py

示例4: makekeyhookevent

# 需要导入模块: from Xlib import X [as 别名]
# 或者: from Xlib.X import KeyPress [as 别名]
def makekeyhookevent(self, keysym, event):
        storewm = self.xwindowinfo()
        if event.type == X.KeyPress:
            MessageName = "key down"
        elif event.type == X.KeyRelease:
            MessageName = "key up"
        return pyxhookkeyevent(
            storewm["handle"],
            storewm["name"],
            storewm["class"],
            self.lookup_keysym(keysym),
            self.asciivalue(keysym),
            False,
            event.detail,
            MessageName
        ) 
开发者ID:nikhilkumarsingh,项目名称:clix,代码行数:18,代码来源:pyxhook.py

示例5: __sendKeyPressEvent

# 需要导入模块: from Xlib import X [as 别名]
# 或者: from Xlib.X import KeyPress [as 别名]
def __sendKeyPressEvent(self, keyCode, modifiers, theWindow=None):
        if theWindow is None:
            focus = self.localDisplay.get_input_focus().focus
        else:
            focus = theWindow
        keyEvent = event.KeyPress(
                                  detail=keyCode,
                                  time=X.CurrentTime,
                                  root=self.rootWindow,
                                  window=focus,
                                  child=X.NONE,
                                  root_x=1,
                                  root_y=1,
                                  event_x=1,
                                  event_y=1,
                                  state=modifiers,
                                  same_screen=1
                                  )
        focus.send_event(keyEvent) 
开发者ID:autokey,项目名称:autokey,代码行数:21,代码来源:interface.py

示例6: run

# 需要导入模块: from Xlib import X [as 别名]
# 或者: from Xlib.X import KeyPress [as 别名]
def run(self):
        # Create a recording context; we only want key and mouse events
        self.ctx = self.recordDisplay.record_create_context(
                0,
                [record.AllClients],
                [{
                        'core_requests': (0, 0),
                        'core_replies': (0, 0),
                        'ext_requests': (0, 0, 0, 0),
                        'ext_replies': (0, 0, 0, 0),
                        'delivered_events': (0, 0),
                        'device_events': (X.KeyPress, X.ButtonPress), #X.KeyRelease,
                        'errors': (0, 0),
                        'client_started': False,
                        'client_died': False,
                }])

        # Enable the context; this only returns after a call to record_disable_context,
        # while calling the callback function in the meantime
        logger.info("XRecord interface thread starting")
        self.recordDisplay.record_enable_context(self.ctx, self.__processEvent)
        # Finally free the context
        self.recordDisplay.record_free_context(self.ctx)
        self.recordDisplay.close() 
开发者ID:autokey,项目名称:autokey,代码行数:26,代码来源:interface.py

示例7: __processEvent

# 需要导入模块: from Xlib import X [as 别名]
# 或者: from Xlib.X import KeyPress [as 别名]
def __processEvent(self, reply):
        if reply.category != record.FromServer:
            return
        if reply.client_swapped:
            return
        if not len(reply.data) or str_or_bytes_to_bytes(reply.data)[0] < 2:
            # not an event
            return

        data = reply.data
        while len(data):
            event, data = rq.EventField(None).parse_binary_value(data, self.recordDisplay.display, None, None)
            if event.type == X.KeyPress:
                self.handle_keypress(event.detail)
            elif event.type == X.KeyRelease:
                self.handle_keyrelease(event.detail)
            elif event.type == X.ButtonPress:
                self.handle_mouseclick(event.detail, event.root_x, event.root_y) 
开发者ID:autokey,项目名称:autokey,代码行数:20,代码来源:interface.py

示例8: handle_event

# 需要导入模块: from Xlib import X [as 别名]
# 或者: from Xlib.X import KeyPress [as 别名]
def handle_event(self, event):

        # KeyPress event
        if event.type == X.KeyPress:
            keyname = xrobot.get_keyname(event)
            self.keyPressed.emit(keyname)

        # KeyRelease event
        elif event.type == X.KeyRelease:
            keyname = xrobot.get_keyname(event)
            self.keyReleased.emit(keyname)

        # ButtonPress event
        elif event.type == X.ButtonPress:
            self.buttonPressed.emit(event.root_x, event.root_y, event.time)

        # ButtonRelease event
        elif event.type == X.ButtonRelease:
            self.buttonReleased.emit(event.root_x, event.root_y, event.time)

        # MotionNotify event
        elif event.type == X.MotionNotify:
            self.cursorPositionChanged.emit(event.root_x, event.root_y) 
开发者ID:linuxdeepin,项目名称:deepin-remote-assistance,代码行数:25,代码来源:event.py

示例9: press

# 需要导入模块: from Xlib import X [as 别名]
# 或者: from Xlib.X import KeyPress [as 别名]
def press(self, key, mask=X.NONE):
        keycode = self.string_to_keycode(key)
        self.inkscape.send_event(self.event(event.KeyPress, keycode, mask), propagate=True)
        self.inkscape.send_event(self.event(event.KeyRelease, keycode, mask), propagate=True)
        self.disp.flush()
        self.disp.sync() 
开发者ID:gillescastel,项目名称:inkscape-shortcut-manager,代码行数:8,代码来源:main.py

示例10: _check_event

# 需要导入模块: from Xlib import X [as 别名]
# 或者: from Xlib.X import KeyPress [as 别名]
def _check_event(self, source, condition, handle=None):
        """ Check keyboard event has all the right buttons pressed. """
        handle = handle or self.root.display
        for _ in range(0, handle.pending_events()):
            event = handle.next_event()
            if event.type == X.KeyPress:
                command = self.keys[event.detail]
                self._handle_event(command)
        return True 
开发者ID:pkkid,项目名称:pygrid,代码行数:11,代码来源:pygrid.py

示例11: key_down

# 需要导入模块: from Xlib import X [as 别名]
# 或者: from Xlib.X import KeyPress [as 别名]
def key_down(self, key):
        """Performs a keyboard key press without the release. This will put that key in a held down state.

        :param key: The key to be pressed down. The valid names are listed in Key class
        :return: None.
        """
        if isinstance(key, Key) or isinstance(key, KeyModifier):
            key = key.value.x11key

        if self.keyboard_mapping(key) is None:
            return

        if isinstance(key, int):
            fake_input(self.display, X.KeyPress, key)
            self.display.sync()
            return

        needs_shift = is_shift_character(key)
        if needs_shift:
            fake_input(self.display, X.KeyPress, self.keyboard_mapping("shift"))

        fake_input(self.display, X.KeyPress, self.keyboard_mapping(key))

        if needs_shift:
            fake_input(self.display, X.KeyRelease, self.keyboard_mapping("shift"))
        self.display.sync() 
开发者ID:mozilla,项目名称:iris,代码行数:28,代码来源:keyboard.py

示例12: run

# 需要导入模块: from Xlib import X [as 别名]
# 或者: from Xlib.X import KeyPress [as 别名]
def run(self):
        # Check if the extension is present
        if not self.record_dpy.has_extension("RECORD"):
            print ("RECORD extension not found")
            sys.exit(1)
        r = self.record_dpy.record_get_version(0, 0)
        print ("RECORD extension version %d.%d" % (r.major_version, r.minor_version))

        # Create a recording context; we only want key and mouse events
        self.ctx = self.record_dpy.record_create_context(
                0,
                [record.AllClients],
                [{
                        'core_requests': (0, 0),
                        'core_replies': (0, 0),
                        'ext_requests': (0, 0, 0, 0),
                        'ext_replies': (0, 0, 0, 0),
                        'delivered_events': (0, 0),
                        'device_events': tuple(self.contextEventMask), #(X.KeyPress, X.ButtonPress),
                        'errors': (0, 0),
                        'client_started': False,
                        'client_died': False,
                }])

        # Enable the context; this only returns after a call to record_disable_context,
        # while calling the callback function in the meantime
        self.record_dpy.record_enable_context(self.ctx, self.processevents)
        # Finally free the context
        self.record_dpy.record_free_context(self.ctx) 
开发者ID:OmkarPathak,项目名称:Python-Programs,代码行数:31,代码来源:pyxhook.py

示例13: HookKeyboard

# 需要导入模块: from Xlib import X [as 别名]
# 或者: from Xlib.X import KeyPress [as 别名]
def HookKeyboard(self):
        pass
        # We don't need to do anything here anymore, since the default mask 
        # is now set to contain X.KeyPress
        #self.contextEventMask[0] = X.KeyPress 
开发者ID:OmkarPathak,项目名称:Python-Programs,代码行数:7,代码来源:pyxhook.py

示例14: processevents

# 需要导入模块: from Xlib import X [as 别名]
# 或者: from Xlib.X import KeyPress [as 别名]
def processevents(self, reply):
        if reply.category != record.FromServer:
            return
        if reply.client_swapped:
            print ("* received swapped protocol data, cowardly ignored")
            return
        if not len(reply.data) or reply.data[0] < 2:
            # not an event
            return
        data = reply.data
        while len(data):
            event, data = rq.EventField(None).parse_binary_value(data, self.record_dpy.display, None, None)
            if event.type == X.KeyPress:
                hookevent = self.keypressevent(event)
                self.KeyDown(hookevent)
            elif event.type == X.KeyRelease:
                hookevent = self.keyreleaseevent(event)
                self.KeyUp(hookevent)
            elif event.type == X.ButtonPress:
                hookevent = self.buttonpressevent(event)
                self.MouseAllButtonsDown(hookevent)
            elif event.type == X.ButtonRelease:
                hookevent = self.buttonreleaseevent(event)
                self.MouseAllButtonsUp(hookevent)
            elif event.type == X.MotionNotify:
                # use mouse moves to record mouse position, since press and release events
                # do not give mouse position info (event.root_x and event.root_y have 
                # bogus info).
                self.mousemoveevent(event)
        
        #print "processing events...", event.type 
开发者ID:OmkarPathak,项目名称:Python-Programs,代码行数:33,代码来源:pyxhook.py

示例15: makekeyhookevent

# 需要导入模块: from Xlib import X [as 别名]
# 或者: from Xlib.X import KeyPress [as 别名]
def makekeyhookevent(self, keysym, event):
        storewm = self.xwindowinfo()
        if event.type == X.KeyPress:
            MessageName = "key down"
        elif event.type == X.KeyRelease:
            MessageName = "key up"
        return pyxhookkeyevent(storewm["handle"], storewm["name"], storewm["class"], self.lookup_keysym(keysym), self.asciivalue(keysym), False, event.detail, MessageName) 
开发者ID:OmkarPathak,项目名称:Python-Programs,代码行数:9,代码来源:pyxhook.py


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