Implemented basice linear acceleration.... This makes it more usable, ill update if PR is accepted
This commit is contained in:
parent
a627102b52
commit
25fd205c3e
@ -1,3 +1,5 @@
|
||||
from micropython import const
|
||||
from supervisor import ticks_ms
|
||||
from kmk.hid import HID_REPORT_SIZES, HIDReportTypes
|
||||
from kmk.keys import make_key
|
||||
from kmk.modules import Module
|
||||
@ -10,6 +12,7 @@ class PointingDevice:
|
||||
_evt = bytearray(HID_REPORT_SIZES[HIDReportTypes.MOUSE] + 1)
|
||||
|
||||
def __init__(self):
|
||||
self.key_states = {}
|
||||
self.hid_pending = False
|
||||
self.report_device = memoryview(self._evt)[0:1]
|
||||
self.report_device[0] = HIDReportTypes.MOUSE
|
||||
@ -19,10 +22,20 @@ class PointingDevice:
|
||||
self.report_w = memoryview(self._evt)[4:]
|
||||
|
||||
|
||||
|
||||
|
||||
class MouseKeys(Module):
|
||||
def __init__(self):
|
||||
self.move_step = 1
|
||||
self.pointing_device = PointingDevice()
|
||||
self.nav_key_activated=0
|
||||
self.up_activated = False
|
||||
self.down_activated = False
|
||||
self.left_activated = False
|
||||
self.right_activated = False
|
||||
self.max_speed = 10
|
||||
self.ac_interval = 100 # Delta ms to apply acceleration
|
||||
self._next_interval = 0 # Time for next tick interval
|
||||
self.move_step = 1
|
||||
|
||||
make_key(
|
||||
names=('MB_LMB',),
|
||||
@ -40,7 +53,9 @@ class MouseKeys(Module):
|
||||
on_release=self._mb_rmb_release,
|
||||
)
|
||||
make_key(
|
||||
names=('MW_UP',), on_press=self._mw_up_press, on_release=self._mw_up_release
|
||||
names=('MW_UP',),
|
||||
on_press=self._mw_up_press,
|
||||
on_release=self._mw_up_release,
|
||||
)
|
||||
make_key(
|
||||
names=(
|
||||
@ -51,7 +66,9 @@ class MouseKeys(Module):
|
||||
on_release=self._mw_down_release,
|
||||
)
|
||||
make_key(
|
||||
names=('MS_UP',), on_press=self._ms_up_press, on_release=self._ms_y_release
|
||||
names=('MS_UP',),
|
||||
on_press=self._ms_up_press,
|
||||
on_release=self._ms_up_release,
|
||||
)
|
||||
make_key(
|
||||
names=(
|
||||
@ -59,7 +76,7 @@ class MouseKeys(Module):
|
||||
'MS_DN',
|
||||
),
|
||||
on_press=self._ms_down_press,
|
||||
on_release=self._ms_y_release,
|
||||
on_release=self._ms_down_release,
|
||||
)
|
||||
make_key(
|
||||
names=(
|
||||
@ -67,7 +84,7 @@ class MouseKeys(Module):
|
||||
'MS_LT',
|
||||
),
|
||||
on_press=self._ms_left_press,
|
||||
on_release=self._ms_x_release,
|
||||
on_release=self._ms_left_release,
|
||||
)
|
||||
make_key(
|
||||
names=(
|
||||
@ -75,16 +92,36 @@ class MouseKeys(Module):
|
||||
'MS_RT',
|
||||
),
|
||||
on_press=self._ms_right_press,
|
||||
on_release=self._ms_x_release,
|
||||
on_release=self._ms_right_release,
|
||||
)
|
||||
|
||||
def during_bootup(self, keyboard):
|
||||
return
|
||||
|
||||
def matrix_detected_press(self, keyboard):
|
||||
return keyboard.matrix_update is None
|
||||
|
||||
def before_matrix_scan(self, keyboard):
|
||||
return
|
||||
|
||||
def after_matrix_scan(self, keyboard):
|
||||
if self.nav_key_activated:
|
||||
if self._next_interval <= ticks_ms():
|
||||
# print("hello: ")
|
||||
# print(ticks_ms())
|
||||
self._next_interval = ticks_ms() + self.ac_interval
|
||||
# print(self._next_interval)
|
||||
if self.move_step < self.max_speed:
|
||||
self.move_step = self.move_step + 1
|
||||
if self.right_activated:
|
||||
self.pointing_device.report_x[0] = self.move_step
|
||||
if self.left_activated:
|
||||
self.pointing_device.report_x[0] = 0xFF & (0 - self.move_step)
|
||||
if self.up_activated:
|
||||
self.pointing_device.report_y[0] = 0xFF & (0 - self.move_step)
|
||||
if self.down_activated:
|
||||
self.pointing_device.report_y[0] = self.move_step
|
||||
#self.pointing_device.hid_pending = True
|
||||
return
|
||||
|
||||
def before_hid_send(self, keyboard):
|
||||
@ -142,27 +179,69 @@ class MouseKeys(Module):
|
||||
self.pointing_device.hid_pending = True
|
||||
|
||||
# Mouse movement
|
||||
def _reset_next_interval(self):
|
||||
if self.nav_key_activated == 1:
|
||||
self._next_interval = ticks_ms() + self.ac_interval
|
||||
self.move_step=1
|
||||
|
||||
def _check_last(self):
|
||||
if self.nav_key_activated == 0:
|
||||
self.move_step=1
|
||||
|
||||
def _ms_up_press(self, key, keyboard, *args, **kwargs):
|
||||
self.nav_key_activated+=1
|
||||
self._reset_next_interval()
|
||||
self.up_activated = True
|
||||
self.pointing_device.report_y[0] = 0xFF & (0 - self.move_step)
|
||||
self.pointing_device.hid_pending = True
|
||||
|
||||
def _ms_up_release(self, key, keyboard, *args, **kwargs):
|
||||
self.up_activated = False
|
||||
self.nav_key_activated-=1
|
||||
self._check_last()
|
||||
self.pointing_device.report_y[0] = 0
|
||||
self.pointing_device.hid_pending = False
|
||||
|
||||
def _ms_down_press(self, key, keyboard, *args, **kwargs):
|
||||
self.nav_key_activated+=1
|
||||
self._reset_next_interval()
|
||||
self.down_activated=True
|
||||
# if not self.x_activated and not self.y_activated:
|
||||
# self.next_interval = ticks_ms() + self.ac_intervalle
|
||||
self.pointing_device.report_y[0] = self.move_step
|
||||
self.pointing_device.hid_pending = True
|
||||
|
||||
def _ms_y_release(self, key, keyboard, *args, **kwargs):
|
||||
def _ms_down_release(self, key, keyboard, *args, **kwargs):
|
||||
self.down_activated = False
|
||||
self.nav_key_activated-=1
|
||||
self._check_last()
|
||||
self.pointing_device.report_y[0] = 0
|
||||
self.pointing_device.hid_pending = False
|
||||
|
||||
def _ms_left_press(self, key, keyboard, *args, **kwargs):
|
||||
self.nav_key_activated+=1
|
||||
self._reset_next_interval()
|
||||
self.left_activated = True
|
||||
self.pointing_device.report_x[0] = 0xFF & (0 - self.move_step)
|
||||
self.pointing_device.hid_pending = True
|
||||
|
||||
def _ms_left_release(self, key, keyboard, *args, **kwargs):
|
||||
self.nav_key_activated-=1
|
||||
self.left_activated = False
|
||||
self._check_last()
|
||||
self.pointing_device.report_x[0] = 0
|
||||
self.pointing_device.hid_pending = False
|
||||
|
||||
def _ms_right_press(self, key, keyboard, *args, **kwargs):
|
||||
self.nav_key_activated+=1
|
||||
self._reset_next_interval()
|
||||
self.right_activated = True
|
||||
self.pointing_device.report_x[0] = self.move_step
|
||||
self.pointing_device.hid_pending = True
|
||||
|
||||
def _ms_x_release(self, key, keyboard, *args, **kwargs):
|
||||
def _ms_right_release(self, key, keyboard, *args, **kwargs):
|
||||
self.nav_key_activated-=1
|
||||
self.right_activated = False
|
||||
self._check_last()
|
||||
self.pointing_device.report_x[0] = 0
|
||||
self.pointing_device.hid_pending = False
|
||||
|
Loading…
Reference in New Issue
Block a user