From ca800331de2c7a4e33316cc4c72bb68b128b4a77 Mon Sep 17 00:00:00 2001 From: xs5871 Date: Sat, 22 Oct 2022 20:49:12 +0000 Subject: [PATCH] Implement axis movement method --- kmk/keys.py | 4 ++++ kmk/modules/mouse_keys.py | 15 ++++++--------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/kmk/keys.py b/kmk/keys.py index ba2809b..6cb328b 100644 --- a/kmk/keys.py +++ b/kmk/keys.py @@ -42,6 +42,10 @@ class Axis: def __repr__(self) -> str: return f'Axis(code={self.code}, delta={self.delta})' + def move(self, keyboard: Keyboard, delta: int): + keyboard.hid_pending = True + self.delta += delta + def maybe_make_key( code: Optional[int], diff --git a/kmk/modules/mouse_keys.py b/kmk/modules/mouse_keys.py index fc94fe8..cdbd2b4 100644 --- a/kmk/modules/mouse_keys.py +++ b/kmk/modules/mouse_keys.py @@ -106,21 +106,18 @@ class MouseKeys(Module): if self.move_step < self.max_speed: self.move_step = self.move_step + 1 if self._right_activated: - keyboard.axes['X'].delta += self.move_step + keyboard.axes['X'].move(keyboard, self.move_step) if self._left_activated: - keyboard.axes['X'].delta -= self.move_step + keyboard.axes['X'].move(keyboard, -self.move_step) if self._up_activated: - keyboard.axes['Y'].delta -= self.move_step + keyboard.axes['Y'].move(keyboard, -self.move_step) if self._down_activated: - keyboard.axes['Y'].delta += self.move_step - keyboard.hid_pending = True + keyboard.axes['Y'].move(keyboard, self.move_step) if self._mw_up_activated: - keyboard.axes['W'].delta += self.move_step - keyboard.hid_pending = True + keyboard.axes['W'].move(keyboard, 1) if self._mw_down_activated: - keyboard.axes['W'].delta -= self.move_step - keyboard.hid_pending = True + keyboard.axes['W'].move(keyboard, -1) def before_hid_send(self, keyboard): return