def _process_key_action(self, proto, packet): (_, id, keyname, depressed, modifiers) = packet self._make_keymask_match(modifiers) self._focus(id) log.debug("now %spressing key %s", depressed, keyname) xtest_fake_key(gtk.gdk.display_get_default(), self._keycode(keyname), depressed)
def _make_keymask_match(self, modifier_list): (_, _, current_mask) = gtk.gdk.get_default_root_window().get_pointer() current = set(mask_to_names(current_mask, self._modifier_map)) wanted = set(modifier_list) log.debug("current mask: %s, wanted: %s", current, wanted) for modifier in current.difference(wanted): keyname = self._keyname_for_mod[modifier] log.debug("unpressing %s", keyname) xtest_fake_key(gtk.gdk.display_get_default(), self._keycode(keyname), False) for modifier in wanted.difference(current): keyname = self._keyname_for_mod[modifier] log.debug("pressing %s", keyname) xtest_fake_key(gtk.gdk.display_get_default(), self._keycode(keyname), True)
def change_mask(modifiers, press, info): for modifier in modifiers: if self.xkbmap_mod_managed and modifier in self.xkbmap_mod_managed: debug("modifier is server managed: %s", modifier) continue keynames = self.keynames_for_mod.get(modifier) if not keynames: log.error("unknown modifier: %s", modifier) continue if is_ignored(keynames): debug("modifier %s ignored (in ignored keynames=%s)", modifier, keynames) continue #find the keycodes that match the keynames for this modifier keycodes = [] #log.info("keynames(%s)=%s", modifier, keynames) for keyname in keynames: if keyname in self.keys_pressed.values(): #found the key which was pressed to set this modifier for keycode, name in self.keys_pressed.items(): if name==keyname: debug("found the key pressed for %s: %s", modifier, name) keycodes.insert(0, keycode) keycodes_for_keyname = self.keycodes_for_modifier_keynames.get(keyname) if keycodes_for_keyname: for keycode in keycodes_for_keyname: if keycode not in keycodes: keycodes.append(keycode) if ignored_modifier_keycode is not None and ignored_modifier_keycode in keycodes: debug("modifier %s ignored (ignored keycode=%s)", modifier, ignored_modifier_keycode) continue #nuisance keys (lock, num, scroll) are toggled by a #full key press + key release (so act accordingly in the loop below) nuisance = modifier in DEFAULT_MODIFIER_NUISANCE debug("keynames(%s)=%s, keycodes=%s, nuisance=%s", modifier, keynames, keycodes, nuisance) for keycode in keycodes: if nuisance: xtest_fake_key(display, keycode, True) xtest_fake_key(display, keycode, False) else: xtest_fake_key(display, keycode, press) new_mask = get_current_mask() success = (modifier in new_mask)==press debug("make_keymask_match(%s) %s modifier %s using %s, success: %s", info, modifier_list, modifier, keycode, success) if success: break elif not nuisance: debug("%s %s with keycode %s did not work - trying to undo it!", info, modifier, keycode) xtest_fake_key(display, keycode, not press) new_mask = get_current_mask() #maybe doing the full keypress (down+up or u+down) worked: if (modifier in new_mask)==press: break
def change_mask(modifiers, press, info): for modifier in modifiers: if self.xkbmap_mod_managed and modifier in self.xkbmap_mod_managed: debug("modifier is server managed: %s", modifier) continue keynames = self.keynames_for_mod.get(modifier) if not keynames: log.error("unknown modifier: %s", modifier) continue if is_ignored(keynames): debug("modifier %s ignored (in ignored keynames=%s)", modifier, keynames) continue #find the keycodes that match the keynames for this modifier keycodes = [] #log.info("keynames(%s)=%s", modifier, keynames) for keyname in keynames: if keyname in self.keys_pressed.values(): #found the key which was pressed to set this modifier for keycode, name in self.keys_pressed.items(): if name == keyname: debug("found the key pressed for %s: %s", modifier, name) keycodes.insert(0, keycode) keycodes_for_keyname = self.keycodes_for_modifier_keynames.get( keyname) if keycodes_for_keyname: for keycode in keycodes_for_keyname: if keycode not in keycodes: keycodes.append(keycode) if ignored_modifier_keycode is not None and ignored_modifier_keycode in keycodes: debug("modifier %s ignored (ignored keycode=%s)", modifier, ignored_modifier_keycode) continue #nuisance keys (lock, num, scroll) are toggled by a #full key press + key release (so act accordingly in the loop below) nuisance = modifier in DEFAULT_MODIFIER_NUISANCE debug("keynames(%s)=%s, keycodes=%s, nuisance=%s", modifier, keynames, keycodes, nuisance) for keycode in keycodes: if nuisance: xtest_fake_key(display, keycode, True) xtest_fake_key(display, keycode, False) else: xtest_fake_key(display, keycode, press) new_mask = get_current_mask() success = (modifier in new_mask) == press debug( "make_keymask_match(%s) %s modifier %s using %s, success: %s", info, modifier_list, modifier, keycode, success) if success: break elif not nuisance: debug( "%s %s with keycode %s did not work - trying to undo it!", info, modifier, keycode) xtest_fake_key(display, keycode, not press) new_mask = get_current_mask() #maybe doing the full keypress (down+up or u+down) worked: if (modifier in new_mask) == press: break
def press_unpress(keys): for k in keys: xtest_fake_key(self.display, keycode(k), True) for k in reversed(keys): xtest_fake_key(self.display, keycode(k), False)