diff --git a/docs/rapidfire.md b/docs/rapidfire.md index 7a324cb..fa137ef 100644 --- a/docs/rapidfire.md +++ b/docs/rapidfire.md @@ -28,7 +28,7 @@ The RapidFire keycode has a few different options: | `wait` | `200` | The delay before starting to repeat. Useful if you want to be able to type with keys that have a low `repeat` value. | | `randomize_repeat` | `False` | Randomize the value of `repeat`. Useful for making the repetitive input look human in instances where you may be flagged as a bot otherwise. | | `randomize_magnitude` | `15` | The magnitude of the randomization. If randomization is enabled, the repeat delay will be `repeat` plus or minus a random value up to this amount. | -| `toggle` | `False` | Toggle RapidFire state on keypress rather than needing to be held. | +| `toggle` | `False` | Toggle RapidFire state on keypress rather than needing to be held. Toggle functionality starts after the `wait` period. | ### Example Code diff --git a/kmk/modules/rapidfire.py b/kmk/modules/rapidfire.py index 24b742b..e022806 100644 --- a/kmk/modules/rapidfire.py +++ b/kmk/modules/rapidfire.py @@ -25,6 +25,7 @@ class RapidFireMeta: class RapidFire(Module): _active_keys = {} _toggled_keys = [] + _waiting_keys = [] def __init__(self): make_argumented_key( @@ -43,6 +44,8 @@ class RapidFire(Module): def _on_timer_timeout(self, key, keyboard): keyboard.tap_key(key.meta.kc) + if key in self._waiting_keys: + self._waiting_keys.remove(key) self._active_keys[key] = keyboard.set_timeout( self._get_repeat(key), lambda: self._on_timer_timeout(key, keyboard) ) @@ -50,19 +53,28 @@ class RapidFire(Module): def _rf_pressed(self, key, keyboard, *args, **kwargs): if key in self._toggled_keys: self._toggled_keys.remove(key) - self._rf_released(key, keyboard) + self._deactivate_key(key, keyboard) return keyboard.tap_key(key.meta.kc) if key.meta.toggle: self._toggled_keys.append(key) + self._waiting_keys.append(key) self._active_keys[key] = keyboard.set_timeout( key.meta.wait, lambda: self._on_timer_timeout(key, keyboard) ) def _rf_released(self, key, keyboard, *args, **kwargs): - if key in self._active_keys and key not in self._toggled_keys: - keyboard.cancel_timeout(self._active_keys[key]) - self._active_keys.pop(key) + if key not in self._active_keys: + return + if key in self._toggled_keys: + if key not in self._waiting_keys: + return + self._toggled_keys.remove(key) + self._deactivate_key(key, keyboard) + + def _deactivate_key(self, key, keyboard): + keyboard.cancel_timeout(self._active_keys[key]) + self._active_keys.pop(key) def during_bootup(self, keyboard): return