def TextboxPreviewKeyDown(self, sender, e): log.info('preview key down') ctrl, alt, shift = [(Control.ModifierKeys & modifier) == modifier for modifier in (Keys.Control, Keys.Alt, Keys.Shift)] modifiers = filter(bool, [ctrl and 'Ctrl', alt and 'Alt', shift and 'Shift']) self._status.Text = '+'.join(modifiers + [str(e.KeyCode)]) modifiers = [e.Control and 'c', e.Alt and 'a', e.Shift and 's']#, #e.Win and 'w'] modifiers = ''.join(filter(bool, modifiers)) prefix = modifiers and modifiers + '-' or '' if e.KeyCode in keys: key = keys[e.KeyCode] elif e.KeyCode in (Keys.ControlKey, Keys.ShiftKey): key = None else: key = str(e.KeyCode) if key in set(string.uppercase): key = key.lower() if key: self.handling_keypress = True zmq.send_command(prefix + key) return True
def TextboxSelectionChanged(self, sender, e): if self.handling_keypress: return True start, length = sender.SelectionStart, sender.SelectionLength text = sender.Text log.info('selection changed, text="%s" [%d:%d]', repr(text), start, length) if self.text.text != text: self.text, text_delta = self.text.set_text(text) else: text_delta = [] self.text, selection_delta = self.text.set_selection(start, length) delta = text_delta + selection_delta for op in delta: if isinstance(op, basestring): zmq.send_key(op) else: command, key, count = op for _ in range(count): zmq.send_command(key) return True
def intercepted_key(self, e): log.info('intercepted key event') # FIXME: Split key intercept handling out of this program # FIXME: abstract key processing to a helper module; replace key # processing here and in preview key down # should always be a modifier modifier, keyname = e.Key.split('-', 1) # http://www.codeproject.com/Articles/6768/Tips-about-NET-Enums key = Enum.Parse(Keys, keyname) if key in keys: key = keys[key] key = str(key) if key in set(string.uppercase): key = key.lower() key = '-'.join((modifier, key)) log.info('intercepted key: ' + key) zmq.send_command(key)