Make toggle functionality start after wait period
This commit is contained in:
parent
b55942731d
commit
6033dc91d0
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user