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


Python Xlib.XK类代码示例

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


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

示例1: send_paste_keypress

    def send_paste_keypress(self):
        # TODO: configuration option for paste key-sequence?
        ctrl = self.display.keysym_to_keycode(XK.string_to_keysym("Control_L"))
        shift = self.display.keysym_to_keycode(XK.string_to_keysym("Shift_L"))
        v = self.display.keysym_to_keycode(XK.string_to_keysym("v"))

        if self.new_clip:
            ins = self.display.keysym_to_keycode(XK.string_to_keysym("Insert"))
            self.display.xtest_fake_input(X.KeyPress, shift)
            self.display.xtest_fake_input(X.KeyPress, ins)
            self.display.xtest_fake_input(X.KeyRelease, ins)
            self.display.xtest_fake_input(X.KeyRelease, shift)
        else:
            term = self.name in self.terminals or "bash" in self.name
            if term:
                self.display.xtest_fake_input(X.KeyPress, shift)
            self.display.xtest_fake_input(X.KeyPress, ctrl)
            self.display.xtest_fake_input(X.KeyPress, v)
            self.display.xtest_fake_input(X.KeyRelease, v)
            self.display.xtest_fake_input(X.KeyRelease, ctrl)
            if term:
                self.display.xtest_fake_input(X.KeyRelease, shift)

        self.display.sync()

        # need to give xlib time to do it's thing as the calls are asyncronous
        if self.old_text:
            gobject.timeout_add(200, self.reset_clipboard, self.old_text)
        #            self.reset_clipboard (self.old_text)
        else:
            gobject.timeout_add(200, self.clear_clipboard)
开发者ID:jeffrangel,项目名称:gpasteitin-revised,代码行数:31,代码来源:gpasteitin.py

示例2: lookup_character_value

 def lookup_character_value(self, character):
     """
     Looks up the keysym for the character then returns the keycode mapping
     and modifier for that keysym.
     """
     ch_keysym = XK.string_to_keysym(character)
     ch_mask = 0
     if ch_keysym == 0:
         if character in SPECIAL_X_KEYSYMS:
             ch_keysym = XK.string_to_keysym(SPECIAL_X_KEYSYMS[character])
         elif len(character) == 1:
             ch_keysym = ord(character)
     ch_keycodes = self.display.keysym_to_keycodes(ch_keysym)
     
     if len(ch_keycodes) == 0 and len(character) == 1:
         ch_keycodes = self.display.keysym_to_keycodes(ord(character.lower()))
         ch_mask ^= X.LockMask
         
     if len(ch_keycodes) > 0:
         ch_keycode, mask = self.__findUsableKeycode(ch_keycodes)
         if ch_keycode == None or mask == None:
             return None, None
         else:
             ch_mask ^= mask
     else:
         return None, None
     
     if ch_mask ^ 4 < 4:
         ch_mask ^= 4
         ch_mask ^= self.modmasks[self.alt_gr_key]
     
     return ch_keycode, ch_mask
开发者ID:nicolaselie,项目名称:pykuli,代码行数:32,代码来源:x11.py

示例3: register_keystroke_handler

  def register_keystroke_handler(self, keystring, method, context=WMActions.root_context):
    """ Register a callback for a keystroke
    Args:
      keystring: string, format is 'mod1+mod2+modN+key'
         such as 'alt+j'
      method: method to be called
    """
    data = keystring.split("+")
    mod_list = data[:-1]
    key = data[-1]
    modifier_mask = 0
    keysym = XK.string_to_keysym(key)
    #print "%s => %s" % (key, keysym)
    if keysym == X.NoSymbol:
      print "%r is not a valid keysym" % key
      return
    keycode = self.display.keysym_to_keycode(keysym)
    for mod in mod_list:
      # Rename "alt" to "Alt_L" and such.
      if mod in ("alt", "super", "meta"):
        mod = mod.capitalize() + "_L"
      modkey = self.display.keysym_to_keycode(XK.string_to_keysym(mod))
      if modkey in self.modifier_map:
        modifier_mask |= self.modifier_map[modkey]
      else:
        print "Invalid modifier key: '%s' (check xmodmap output)" % mod

    if context == WMActions.root_context:
      for screen in self.screens.itervalues():
        self.grab_key(screen.root, keysym, modifier_mask)
    keybinding = (context, keysym, modifier_mask)
    print "Registered keystroke '%s' as %r)" % (keystring, keybinding,)
    self.keybindings[keybinding] = method
开发者ID:jordansissel,项目名称:ifwm,代码行数:33,代码来源:ifwm.py

示例4: _xlib_get_keycode

 def _xlib_get_keycode(self, key) :
     keysym = XK.string_to_keysym(key)
     if keysym == 0:
         try:
             keysym = XK.string_to_keysym(special_X_keysyms[key])
         except KeyError:
             return None
     keycode = self.disp.keysym_to_keycode(keysym)
     return keycode
开发者ID:timeyyy,项目名称:system_hotkey,代码行数:9,代码来源:system_hotkey.py

示例5: find_key

def find_key(key):
	if key == 18:
		return d.keysym_to_keycode(XK.string_to_keysym('Left'))
	elif key == 50:
		return d.keysym_to_keycode(XK.string_to_keysym('Right'))
	elif key == 34:
		return d.keysym_to_keycode(XK.string_to_keysym('Home'))
	else:
		return 0
开发者ID:fmgoncalves,项目名称:eZ430-tools,代码行数:9,代码来源:ppt.py

示例6: setup_funnylocks

 def setup_funnylocks(self):
     nlock_key = self.dpy.keysym_to_keycode(XK.string_to_keysym("Num_Lock"))
     slock_key = self.dpy.keysym_to_keycode(XK.string_to_keysym("Scroll_Lock"))
     mapping = self.dpy.get_modifier_mapping()
     mod_names = "Shift Lock Control Mod1 Mod2 Mod3 Mod4 Mod5".split()
     for modname in mod_names:
         index = getattr(X, "%sMapIndex" % modname)
         mask = getattr(X, "%sMask" % modname)
         if nlock_key and nlock_key in mapping[index]:
             self.nlock = mask
         if slock_key and slock_key in mapping[index]:
             self.slock = mask
开发者ID:Luiji,项目名称:whimsy,代码行数:12,代码来源:modifiers.py

示例7: __init__

    def __init__(self, main_instance):
        """ Constructor """
        gobject.GObject.__init__(self)
        threading.Thread.__init__(self)
        self.setDaemon(True)
        self.running = False
        self.main = main_instance

        try:
            XK.load_keysym_group("xf86")
        except ImportError, err:
            log.warn("Xlib backend needs python-xlib 0.15rc1 or higher\n")
            raise ImportError(str(err))
开发者ID:JustinHop,项目名称:volti,代码行数:13,代码来源:xlibevent.py

示例8: string_to_keycode

def string_to_keycode(key):
    #'\r':'Return' for Shift+Return will trigger "\r" and enter string_to_keycode() refer: https://github.com/SavinaRoja/PyKeyboard/blob/master/pykeyboard/x11.py
    keys_special={' ':'space','\t':'Tab','\r':'Return','\n':'Return','\b':'BackSpace','\e':'Escape',
                  '!':'exclam','#':'numbersign','%':'percent','$':'dollar','&':'ampersand','"':'quotedbl',
                  '\'':'apostrophe','(':'parenleft',')':'parenright','*':'asterisk','=':'equal','+':'plus',
                  ',':'comma','-':'minus','.':'period','/':'slash',':':'colon',';':'semicolon','<':'less',
                  '>':'greater','?':'question','@':'at','[':'bracketleft',']':'bracketright','\\':'backslash',
                  '^':'asciicircum','_':'underscore','`':'grave','{':'braceleft','|':'bar','}':'braceright',
                  '~':'asciitilde'
                 }
    key_sym=XK.string_to_keysym(key)
    if key_sym==0:
       key_sym=XK.string_to_keysym(keys_special[key])
    return disp.keysym_to_keycode(key_sym)
开发者ID:diyism,项目名称:MyBoard,代码行数:14,代码来源:myboard.py

示例9: parse_keys

    def parse_keys(self, display, config):

        commands = ['next_window',
                    'prev_window',
                    'kill_window',
                    'split_horizontal',
                    'split_vertical',
                    'next_stack',
                    'prev_stack',
                    'kill_stack']

        for command in commands:

            key_def = getattr(config.keys, command)
            (modifier, key) = key_def.split('+')  # TODO Handle multiple modifiers

            if modifier == 'Mod4':
                mod_mask = X.Mod4Mask
            elif modifier == 'Mod3':
                mod_mask = X.Mod3Mask
            elif modifier == 'Mod2':
                mod_mask = X.Mod2Mask
            elif modifier == 'Mod1':
                mod_mask = X.Mod1Mask
            else:
                logging.critical("Command '%s' uses unknown modifier '%s'", command, modifier)
                sys.exit(1)

            keycode = display.keysym_to_keycode(XK.string_to_keysym(key))
            self.keymap[(mod_mask, keycode)] = command
开发者ID:scfrazer,项目名称:ttwm,代码行数:30,代码来源:WmData.py

示例10: __init__

    def __init__(self, display, path=os.path.join(os.path.dirname(os.path.realpath(__file__)), "default.json")):
        self.config = {}

        # Load and parse JSON config
        with open(path) as data_file:
            raw_config = json.load(data_file)

        # Iterate through the items in the object
        for dkey, value in raw_config.iteritems():

            # If a value is not a list type, ignore it
            if type(value) is not list:
                logging.error("Key configurations must be listed in arrays.")
                continue

            # Convert all of the key strings into their proper codes
            self.config[dkey] = []
            for key in value:
                code = XK.string_to_keysym(key)

                # If the returned code is 0, then it could not be found by XK
                if code is 0:
                    self.config[dkey] = None
                    logging.warning("Key ("+code+") was not recognized by XK")
                    break
                else:
                    self.config[dkey].append(display.keysym_to_keycode(code))
开发者ID:AndrewGuenther,项目名称:XLeapr,代码行数:27,代码来源:keyconfig.py

示例11: main

def main(options):
    # current display
    pid_file = "/var/lock/easyxmotion.pid"
    # kill any old versions that are still running,
    # we do it this way so the current one has input focus.
    # might be a better way to just exit and give focus to the old one.
    try:
        with open(pid_file, "r") as fp:
            pid = int(fp.read())
            try:
                os.kill(pid, signal.SIGTERM)
            except OSError:
                # other isn't running
                pass
    except IOError:
        # first ever run
        pass
    with open(pid_file, "w") as fp:
        fp.write(str(os.getpid()))

    osds, windows = display_osd(options)
    disp = Display()
    root = disp.screen().root
    root.change_attributes(event_mask=X.KeyPressMask)
    root.grab_keyboard(False, X.GrabModeAsync, X.GrabModeAsync, X.CurrentTime)

    event = disp.next_event()
    keycode = event.detail
    if event.type == X.KeyPress:
        key = XK.keysym_to_string(disp.keycode_to_keysym(keycode, 0))
        if key and key in string.lowercase and string.lowercase.index(key) < len(windows):
            windows[string.lowercase.index(key)].activate(timestamp)
        disp.ungrab_keyboard(X.CurrentTime)
        sys.exit()
开发者ID:liuexp,项目名称:arch-script,代码行数:34,代码来源:easyxmotion.py

示例12: emulateWritingString

 def emulateWritingString(d, cmd, delay, k=None):
     '''
         Processes a string by writing it to the screen with a certain delay
     '''
     for c in cmd:
         if k is not None:
             # Emulate the key.
             emulateSpecialKey(d, k, delay)
         keysym = XK.string_to_keysym(c)
         if keysym == 0:
             # Its a symbol, not a letter.
             emulateSpecialKey(d, c, delay)
         else:
             # It's a letter
             keycode = d.keysym_to_keycode(keysym)
             # If it's uppercase, we press shift.
             if c.isupper():
                 xtest.fake_input(d, X.KeyPress, kmap[u'shift_l'])
             # Its even a specialer key :P
             if keycode == 0:
                 emulateSpecialKey(d, c, delay)
             else:
                 xtest.fake_input(d, X.KeyPress, keycode)
                 d.flush()
                 time.sleep(delay)
                 xtest.fake_input(d, X.KeyRelease, keycode)
                 # Delay time between letters
     #            time.sleep(0.025)
             # If it's uppercase, we release shift.
             if c.isupper():
                 xtest.fake_input(d, X.KeyRelease, kmap[u'shift_l'])
         d.flush()
开发者ID:roxana-lafuente,项目名称:ResearchLogger,代码行数:32,代码来源:emulate_keyboard.py

示例13: on_snippets_completed

    def on_snippets_completed(self, text):
        self.snippets.hide()

        if text is not None:
            pyperclip.copy(text)

            keysym = XK.string_to_keysym('V')
            keycode = self.display.keysym_to_keycode(keysym)
            ev = protocol.event.KeyPress(
                time=int(time.time()),
                root=self.display.screen().root,
                window=self.focus,
                root_x=0,
                root_y=0,
                event_x=0,
                event_y=0,
                same_screen=0, child=X.NONE,
                state=X.ControlMask,
                detail=keycode
            )

            self.display.send_event(self.focus, ev)
            self.display.sync()
            time.sleep(1)

            pyperclip.copy(self.cb_cache)

        return True
开发者ID:muratovv,项目名称:linux_snippets,代码行数:28,代码来源:main.py

示例14: str2keycode

 def str2keycode(cls, code, key=''):
     """Convert key as string(s) into (modifiers, keycode) pair.
     
     There must be both modifier(s) and key persenti. If you send both
     modifier(s) and key in one string, they must be separated using '-'. 
     Modifiers must be separated using '-'.
     Keys are case insensitive.
     If you want to use upper case use Shift modifier.
     Only modifiers defined in __KEY_MODIFIERS are valid.
     For example: "Ctrl-A", "Super-Alt-x"
     
     """
     code = code.split('-')
     if not key:
         key = code[-1]
         masks = code[:-1]
     else:
         masks = code
     
     # TODO: Check this part... not sure why it looks like that...
     modifiers = 0
     if masks[0]:
         for mask in masks:
             if not mask in cls.__KEY_MODIFIERS.keys():
                 continue
             modifiers = modifiers | cls.__KEY_MODIFIERS[mask]
     else:
         modifiers = X.AnyModifier
     
     keysym = XK.string_to_keysym(key)
     keycode = cls.__DISPLAY.keysym_to_keycode(keysym)
     cls.__KEYCODES[keycode] = key
     return (modifiers, keycode)
开发者ID:dvf1976,项目名称:My-Unix-Stuff,代码行数:33,代码来源:core.py

示例15: handler

    def handler(self, reply):
        """ Self function is called when a xlib event is fired """
        data = reply.data
        while len(data):
            event, data = rq.EventField(None).parse_binary_value(data,
                                                                 self.disp.display,
                                                                 None, None)

            if event.type == X.KeyPress:
                if event.detail == 36:
                    self.record("enter")
                elif event.detail == 22:
                    self.record("backspace")
                elif event.detail == 37:
                    self.record("control")
                elif event.detail == 64:
                    self.record("alt")
                elif event.detail == 108:
                    self.record("alt-gr")
                        
                key = XK.keysym_to_string(
                    self.disp.keycode_to_keysym(event.detail, event.state))

                if key:
                    self.record(key)
开发者ID:david-bergstrom,项目名称:pykeystat,代码行数:25,代码来源:keylistener.py


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