-
Couldn't load subscription status.
- Fork 507
SpacemouseKeys module #1093
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SpacemouseKeys module #1093
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this is basically a copy-paste of the mouse keys module, but having a dozen methods that all don't actually do anything except binding over a parameter is a terrible design pattern.
The movement direction should be an attribute of SpacemouseKey and we only need a single on_press and on_release.
|
So something like the below? for n, names in enumerate(keys):
make_key(
names=names,
on_press=self.on_press,
on_release=self.on_release,
constructor=SpacemouseKey,
direction=1<<n
)or to use the existing for n, names in enumerate(keys):
make_key(
names=names,
on_press=self.on_press,
on_release=self.on_release,
constructor=SpacemouseKey,
code=0x80+n
)or would it be a new |
|
The way it's implemented right now |
kmk/modules/spacemouse_keys.py
Outdated
| def _maybe_start_move(self, mask): | ||
| self._movement |= mask | ||
| if self._movement == mask: | ||
| self._task.restart() | ||
|
|
||
| def _maybe_stop_move(self, mask): | ||
| self._movement &= ~mask | ||
| if not self._movement: | ||
| cancel_task(self._task) | ||
| self._move_step = 0 | ||
|
|
||
| def _on_press(self, key, keyboard, *args, **kwargs): | ||
| self._maybe_start_move(key.code) | ||
|
|
||
| def _on_release(self, key, keyboard, *args, **kwargs): | ||
| self._maybe_stop_move(key.code) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tiny nitpick:
| def _maybe_start_move(self, mask): | |
| self._movement |= mask | |
| if self._movement == mask: | |
| self._task.restart() | |
| def _maybe_stop_move(self, mask): | |
| self._movement &= ~mask | |
| if not self._movement: | |
| cancel_task(self._task) | |
| self._move_step = 0 | |
| def _on_press(self, key, keyboard, *args, **kwargs): | |
| self._maybe_start_move(key.code) | |
| def _on_release(self, key, keyboard, *args, **kwargs): | |
| self._maybe_stop_move(key.code) | |
| def _on_press(self, key, keyboard, *args, **kwargs): | |
| self._movement |= key.code | |
| if self._movement == key.code: | |
| self._task.restart() | |
| def _on_release(self, key, keyboard, *args, **kwargs): | |
| self._movement &= ~key.code | |
| if not self._movement: | |
| cancel_task(self._task) | |
| self._move_step = 0 |
This is a chunk of #1087 for a module that
PR dependencies: #1092