def __s_to_key_raw(self, s): keyval = keysyms.name_to_keycode(s.split('+')[-1]) s = s.lower() state = ('shift+' in s and modifier.SHIFT_MASK or 0) | ( 'ctrl+' in s and modifier.CONTROL_MASK or 0) | ( 'alt+' in s and modifier.MOD1_MASK or 0) return (keyval, state)
def __s_to_key_raw(self, s): keyval = keysyms.name_to_keycode(s.split('+')[-1]) s = s.lower() state = ('shift+' in s and modifier.SHIFT_MASK or 0) | ('ctrl+' in s and modifier.CONTROL_MASK or 0) | ('alt+' in s and modifier.MOD1_MASK or 0) return (keyval, state)
def string_to_event(s): state = 0 code = 0 num_mod = 0 l = s.split("+") for t in l: if t.startswith("Shift"): state |= ST_SHIFT elif t.startswith("Control"): state |= ST_CONTROL elif t.startswith("Alt_L"): state |= ST_ALT_L else: code = keysyms.name_to_keycode(t) return code, state
def feed(session, input): name = '' is_name = False for c in input: if c == '{': name = '' is_name = True elif c == '}': is_name = False print session.process_key_event(keysyms.name_to_keycode(name), 0) print session.get_response() elif is_name: name += c else: print session.process_key_event(ord(c), 0) print session.get_response()
def on_button5_clicked(self, widget): s = self.xml.get_widget('entry2').get_text() if not s or not keysyms.name_to_keycode(s): dlg = self.xml.get_widget('invalid_keysym') dlg.set_markup('<big><b>%s</b></big>' % _('Invalid keysym')) dlg.format_secondary_text(_('This keysym is not valid')) dlg.run() dlg.hide() return True for w, m in [('checkbutton6', 'Ctrl+'), ('checkbutton7', 'Alt+'), ('checkbutton8', 'Shift+')]: if self.xml.get_widget(w).get_active(): s = m + s l, i = self.xml.get_widget('treeview2').get_selection().get_selected() l[i][0] = s return True
def ParseKeySequence(line): """Parse a key sequence. The input key sequence format is same as the DebugKeySequence output result. See the docstring above. Args: line: A string which represents a key sequence. Returns: A list of (keycode, modifier) tuples. """ result_sequence = [] for matched in re.finditer(r'\((\w+), (\w+)\)', line): keycode = keysyms.name_to_keycode(matched.group(1)) mod_str = matched.group(2) mods = 0 if mod_str.find('SHIFT') >= 0: mods |= modifier.SHIFT_MASK if mod_str.find('CONTROL') >= 0: mods |= modifier.CONTROL_MASK if mod_str.find('ALT') >= 0: mods |= modifier.ALT_MASK result_sequence.append((keycode, mods)) return result_sequence
def parse_key_combinations(combo_string): """Emulate a sequence of key combinations. KeyboardCapture instance would normally detect the emulated key events. In order to prevent this, all KeyboardCapture instances are told to ignore the emulated key events. Argument: combo_string -- A string representing a sequence of key combinations. Keys are represented by their names in the IBus keysyms module. For example, the left Alt key is represented by 'Alt_L'. Keys are either separated by a space or a left or right parenthesis. Parentheses must be properly formed in pairs and may be nested. A key immediately followed by a parenthetical indicates that the key is pressed down while all keys enclosed in the parenthetical are pressed and released in turn. For example, Alt_L(Tab) means to hold the left Alt key down, press and release the Tab key, and then release the left Alt key. """ # Convert the argument into a sequence of keycode, event type pairs # that, if executed in order, would emulate the key # combination represented by the argument. keysym_events = [] key_down_stack = [] current_command = [] def press(k): keysym_events.append((k, 0)) def release(k): keysym_events.append((k, modifier.RELEASE_MASK)) for c in combo_string: if c in (' ', '(', ')'): keysym, keycode, state = _parse_key(''.join(current_command)) # keycode means keysym here... keysym = keysyms.name_to_keycode(keystring) # keycode, mods = self._keysym_to_keycode_and_modifiers(keysym) current_command = [] if keysym is keysyms.VoidSymbol: continue if c == ' ': # Record press and release for command's key. press(keysym) release(keysym) elif c == '(': # Record press for command's key. key_down_stack.append(keysym) press(keysym) elif c == ')': # Record press and release for command's key and # release previously held key. press(keysym) release(keysym) if len(key_down_stack): release(key_down_stack.pop()) else: current_command.append(c) # Record final command key. keysym = keysyms.name_to_keycode(''.join(current_command)) #keysym, mods = self._keysym_to_keysym_and_modifiers(keysym) if keysym is not keysyms.VoidSymbol: press(keysym) release(keysym) # Release all keys. for keysym in key_down_stack: release(keysym) return keysym_events
def get_keyvalue(self, state): keysym = self._xkbc.get_keysym(self._symbol_name, self._key_name, state) return keysyms.name_to_keycode(keysym)