def _handle_uinput_macro(self, macro, state, key_states): uc = macro.get_uinput_code() self._consume_keys(key_states) if state == g15driver.KEY_STATE_UP: if macro in self.__repeat_macros and macro.repeat_mode == g15profile.REPEAT_WHILE_HELD: self.__repeat_macros.remove(macro) g15uinput.emit(macro.type, uc, 0) elif state == g15driver.KEY_STATE_DOWN: if macro in self.__repeat_macros: if macro.repeat_mode == g15profile.REPEAT_TOGGLE and macro.repeat_delay != -1: """ For REPEAT_TOGGLE mode with custom repeat rate, we now cancel the repeat timer and defeat the key release. """ self.__repeat_macros.remove(macro) else: """ For REPEAT_TOGGLE mode with default repeat rate, we will send a release if this is the second press. We also defeat the 2nd release. """ g15uinput.emit(macro.type, uc, 0) self.__repeat_macros.remove(macro) self._defeat_release(key_states) else: if macro.repeat_mode == g15profile.REPEAT_TOGGLE: """ Start repeating """ if not macro in self.__repeat_macros: self._defeat_release(key_states) self.__repeat_macros.append(macro) if macro.repeat_delay != -1: """ For the default delay, just let the OS handle the repeat """ self._repeat_uinput(macro, uc) else: """ For the custom delay, send the key press now. We send the first when it is actually released, then start sending further repeats on a timer """ g15uinput.emit(macro.type, uc, 1) self._defeat_release(key_states) elif macro.repeat_mode == g15profile.NO_REPEAT: """ For NO_REPEAT macros we send the release now, and defeat the actual key release that will come later. """ self._send_uinput_keypress(macro, uc) elif macro.repeat_mode == g15profile.REPEAT_WHILE_HELD and macro.repeat_delay != -1: self._send_uinput_keypress(macro, uc) else: g15uinput.emit(macro.type, uc, 1) elif state == g15driver.KEY_STATE_HELD: if macro.repeat_mode == g15profile.REPEAT_WHILE_HELD: if macro.repeat_delay != -1: self.__repeat_macros.append(macro) self._repeat_uinput(macro, uc, False)
def _send_uinput_keypress(self, macro, uc, uinput_repeat=False): g15uinput.locks[macro.type].acquire() try: if uinput_repeat: g15uinput.emit(macro.type, uc, 2) else: g15uinput.emit(macro.type, uc, 1) g15uinput.emit(macro.type, uc, 0) finally: g15uinput.locks[macro.type].release()
def _send_uinput(target, val, state): if val in g15uinput.capabilities: g15uinput.emit(target, g15uinput.capabilities[val], state, True) else: logger.error("Unknown uinput key %s.", val)
def _send_uinput(self, target, val, state): if val in g15uinput.capabilities: g15uinput.emit(target, g15uinput.capabilities[val], state, True) else: logger.error("Unknown uinput key %s.", val)