def update_timestamps(pos: int, e: InputEvent) -> None: """ Update timestamps of last key press. """ global last_press_timestamps new_value = e.timestamp() if e.value == KeyEvent.key_down else None last_press_timestamps[pos] = new_value debug(f'updated timestamp at [{pos}] to {new_value}')
def handle(self, ui: UInput, e: InputEvent, config: Config, pos: int, *args) -> None: debug('-- handling mod tap action --') if e.value == KeyEvent.key_down: mapper.active_tap_actions[pos] = self debug('MT is pressed, pressing modifiers') host.write_press(ui, *self.modifiers) else: mapper.active_tap_actions.pop(pos) host.release_weak_keys(ui, config) debug('MT is released, releasing modifiers') host.write_release(ui, *self.modifiers) since_last_press = (e.timestamp() - mapper.last_press_timestamps[pos]) * 1000 debug(f'since last press: {since_last_press}') debug(f'action is used: {self.used}') if not self.used and since_last_press <= config.tapping_term: debug('writing key press') host.write_tap(ui, self.code) self.used = False
def handle(self, ui: UInput, e: InputEvent, config: Config, pos: int, *args) -> None: debug('-- handling layer tap action --') if e.value == KeyEvent.key_down: mapper.active_tap_actions[pos] = self debug(f'LT is pressed, enabling layer [{self.layer_index}]') mapper.enable_layer(self.layer_index, self, config) else: mapper.active_tap_actions.pop(pos) host.release_weak_keys(ui, config) debug(f'LT is released, disabling layer [{self.layer_index}]') mapper.disable_layer(ui, self.layer_index, config) since_last_press = (e.timestamp() - mapper.last_press_timestamps[pos]) * 1000 debug(f'since last press: {since_last_press}') debug(f'action is used: {self.used}') if not self.used and since_last_press <= config.tapping_term: debug('writing key press') host.write_tap(ui, self.code) self.used = False