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


Python XK.string_to_keysym方法代码示例

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


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

示例1: register_keystroke_handler

# 需要导入模块: from Xlib import XK [as 别名]
# 或者: from Xlib.XK import string_to_keysym [as 别名]
  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,代码行数:35,代码来源:ifwm.py

示例2: lookup_character_value

# 需要导入模块: from Xlib import XK [as 别名]
# 或者: from Xlib.XK import string_to_keysym [as 别名]
 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,代码行数:34,代码来源:x11.py

示例3: send_paste_keypress

# 需要导入模块: from Xlib import XK [as 别名]
# 或者: from Xlib.XK import string_to_keysym [as 别名]
    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,代码行数:33,代码来源:gpasteitin.py

示例4: find_key

# 需要导入模块: from Xlib import XK [as 别名]
# 或者: from Xlib.XK import string_to_keysym [as 别名]
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,代码行数:11,代码来源:ppt.py

示例5: _xlib_get_keycode

# 需要导入模块: from Xlib import XK [as 别名]
# 或者: from Xlib.XK import string_to_keysym [as 别名]
 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,代码行数:11,代码来源:system_hotkey.py

示例6: setup_funnylocks

# 需要导入模块: from Xlib import XK [as 别名]
# 或者: from Xlib.XK import string_to_keysym [as 别名]
 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,代码行数:14,代码来源:modifiers.py

示例7: string_to_keycode

# 需要导入模块: from Xlib import XK [as 别名]
# 或者: from Xlib.XK import string_to_keysym [as 别名]
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,代码行数:16,代码来源:myboard.py

示例8: str2keycode

# 需要导入模块: from Xlib import XK [as 别名]
# 或者: from Xlib.XK import string_to_keysym [as 别名]
 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,代码行数:35,代码来源:core.py

示例9: __init__

# 需要导入模块: from Xlib import XK [as 别名]
# 或者: from Xlib.XK import string_to_keysym [as 别名]
    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,代码行数:29,代码来源:keyconfig.py

示例10: on_snippets_completed

# 需要导入模块: from Xlib import XK [as 别名]
# 或者: from Xlib.XK import string_to_keysym [as 别名]
    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,代码行数:30,代码来源:main.py

示例11: parse_keystring

# 需要导入模块: from Xlib import XK [as 别名]
# 或者: from Xlib.XK import string_to_keysym [as 别名]
 def parse_keystring(self, keystring):
     keys = keystring.split(" + ")
     if len(keys) == 1:
         keyval = XK.string_to_keysym(keys[0].upper())
         modifier_mask = 0
     else:    
         keyval = XK.string_to_keysym(keys[-1].upper())
         modifier_mask = 0
         
         if "Ctrl" in keys[0:-1]:
             modifier_mask |= X.ControlMask
         if "Alt"  in keys[0:-1]:
             modifier_mask |= X.Mod1Mask
         
     # modifier_mask |= X.ShiftMask        
     return (keyval, modifier_mask)
开发者ID:lovesnow,项目名称:qdict,代码行数:18,代码来源:globalkey.py

示例12: emulateWritingString

# 需要导入模块: from Xlib import XK [as 别名]
# 或者: from Xlib.XK import string_to_keysym [as 别名]
 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,代码行数:34,代码来源:emulate_keyboard.py

示例13: parse_keys

# 需要导入模块: from Xlib import XK [as 别名]
# 或者: from Xlib.XK import string_to_keysym [as 别名]
    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,代码行数:32,代码来源:WmData.py

示例14: str2keycode

# 需要导入模块: from Xlib import XK [as 别名]
# 或者: from Xlib.XK import string_to_keysym [as 别名]
 def str2keycode(cls, key):
     """Parse keycode."""
     keysym = XK.string_to_keysym(key)
     keycode = cls.__DISPLAY.keysym_to_keycode(keysym)
     cls.__KEYCODES[keycode] = key
     if keycode == 0:
         raise ValueError('No key specified!')
     return keycode
开发者ID:agwells,项目名称:PyWO-1,代码行数:10,代码来源:xlib.py

示例15: string_to_keycode

# 需要导入模块: from Xlib import XK [as 别名]
# 或者: from Xlib.XK import string_to_keysym [as 别名]
 def string_to_keycode(self, key):
     codes_mod=[50,62,64,108,37,105]
     names_mod=['Shift_L', 'Shift_R', 'Alt_L', 'Alt_R', 'Control_L', 'Control_R']
     if key in names_mod:
        return codes_mod[names_mod.index(key)]
     keys_special={' ':'space','\t':'Tab','\n':'Return','\r':'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 self.disp.keysym_to_keycode(key_sym)
开发者ID:lovesnow,项目名称:qdict,代码行数:19,代码来源:globalkey.py


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