diff --git a/kmk/handlers/layers.py b/kmk/handlers/layers.py index 0e448dd..d436318 100644 --- a/kmk/handlers/layers.py +++ b/kmk/handlers/layers.py @@ -77,7 +77,7 @@ def tg_pressed(key, state, *args, **kwargs): def to_pressed(key, state, *args, **kwargs): """Activates layer and deactivates all other layers""" - state.active_layers = [key.meta.kc] + state.active_layers = [key.meta.layer] state.reversed_active_layers = list(reversed(state.active_layers)) return state diff --git a/kmk/internal_state.py b/kmk/internal_state.py index b27454b..e552c01 100644 --- a/kmk/internal_state.py +++ b/kmk/internal_state.py @@ -67,8 +67,15 @@ class InternalState: else: timeout_key = ticks_ms() + after_ticks + while timeout_key in self.timeouts: + timeout_key += 1 + self.timeouts[timeout_key] = callback - return self + return timeout_key + + def cancel_timeout(self, timeout_key): + if timeout_key in self.timeouts: + del self.timeouts[timeout_key] def process_timeouts(self): if not self.timeouts: diff --git a/kmk/keys.py b/kmk/keys.py index 0272acd..6ec36f0 100644 --- a/kmk/keys.py +++ b/kmk/keys.py @@ -60,7 +60,8 @@ class Key: def _on_press(self, state, coord_int, coord_raw): for fn in self._pre_press_handlers: - fn(self, state, KC, coord_int, coord_raw) + if not fn(self, state, KC, coord_int, coord_raw): + return None ret = self._handle_press(self, state, KC, coord_int, coord_raw) @@ -71,7 +72,8 @@ class Key: def _on_release(self, state, coord_int, coord_raw): for fn in self._pre_release_handlers: - fn(self, state, KC, coord_int, coord_raw) + if not fn(self, state, KC, coord_int, coord_raw): + return None ret = self._handle_release(self, state, KC, coord_int, coord_raw) @@ -110,8 +112,9 @@ class Key: provided for consistency with the internal handlers) - coord_raw (an X,Y tuple of the matrix coordinate - also likely not useful) - The return value of the provided callback is discarded. Exceptions are _not_ - caught, and will likely crash KMK if not handled within your function. + If return value of the provided callback is evaluated to False, press + processing is cancelled. Exceptions are _not_ caught, and will likely + crash KMK if not handled within your function. These handlers are run in attachment order: handlers provided by earlier calls of this method will be executed before those provided by later calls. @@ -156,8 +159,9 @@ class Key: provided for consistency with the internal handlers) - coord_raw (an X,Y tuple of the matrix coordinate - also likely not useful) - The return value of the provided callback is discarded. Exceptions are _not_ - caught, and will likely crash KMK if not handled within your function. + If return value of the provided callback evaluates to False, the release + processing is cancelled. Exceptions are _not_ caught, and will likely crash + KMK if not handled within your function. These handlers are run in attachment order: handlers provided by earlier calls of this method will be executed before those provided by later calls.