review updates and renamed to Sticky Mod
This commit is contained in:
parent
a0efbb92d5
commit
660b751c87
@ -1,22 +0,0 @@
|
||||
# ModHoldAndTap
|
||||
This module allows to immitate the behaviour of ATL+TAB or CMD+TAB, etc.
|
||||
Basically, it will hold the mod and tap a key. The mod will be released when any other key is pressed or the layer key is released.
|
||||
|
||||
## Enabling the module
|
||||
```python
|
||||
from kmk.module.modholdandtap import ModHoldAndTap
|
||||
modholdandtap = ModHoldAndTap()
|
||||
keyboard.modules.append(modholdandtap)
|
||||
keyboard.keymap = [
|
||||
[
|
||||
KC.MHAT(kc=KC.TAB, mod=KC.LALT),
|
||||
KC.MHAT(KC.TAB, KC.LSFT(KC.LALT)),
|
||||
],
|
||||
]
|
||||
```
|
||||
|
||||
## Keycodes
|
||||
|
||||
|Key |Description |
|
||||
|-------------------------|-----------------------------------------------|
|
||||
|`KC.MHAT(KC.key, KC.mod)`|holds the mod and taps the key |
|
22
docs/sticky_mod.md
Normal file
22
docs/sticky_mod.md
Normal file
@ -0,0 +1,22 @@
|
||||
# Sticky Mod
|
||||
This module allows to immitate the behaviour of ATL+TAB or CMD+TAB, etc. for switching between open windows.
|
||||
The mod will be on hold and the key will be tapped. The mod will be released when any other key is pressed or the layer key is released.
|
||||
|
||||
## Enabling the module
|
||||
```python
|
||||
from kmk.module.sticky_mod import StickyMod
|
||||
sticky_mod = StickyMod()
|
||||
keyboard.modules.append(sticky_mod)
|
||||
keyboard.keymap = [
|
||||
[
|
||||
KC.SM(kc=KC.TAB, mod=KC.LALT),
|
||||
KC.SM(KC.TAB, KC.LSFT(KC.LALT)),
|
||||
],
|
||||
]
|
||||
```
|
||||
|
||||
## Keycodes
|
||||
|
||||
|Key |Description |
|
||||
|-------------------------|-----------------------------------------------|
|
||||
|`KC.SM(KC.key, KC.mod)` |sticky mod |
|
@ -1,65 +0,0 @@
|
||||
from kmk.keys import make_argumented_key
|
||||
from kmk.modules import Module
|
||||
|
||||
|
||||
class ModHoldAndTapValidator:
|
||||
def __init__(self, kc, mod):
|
||||
self.kc = kc
|
||||
self.mod = mod
|
||||
|
||||
|
||||
class ModHoldAndTap(Module):
|
||||
def __init__(self):
|
||||
self._timeout_key = False
|
||||
self._active = False
|
||||
self._prev_key = None
|
||||
make_argumented_key(
|
||||
names=('MHAT',),
|
||||
validator=ModHoldAndTapValidator,
|
||||
)
|
||||
|
||||
def during_bootup(self, keyboard):
|
||||
return
|
||||
|
||||
def before_matrix_scan(self, keyboard):
|
||||
return
|
||||
|
||||
def process_key(self, keyboard, key, is_pressed, int_coord):
|
||||
if isinstance(key.meta, ModHoldAndTapValidator):
|
||||
|
||||
if self._active and self._prev_key is not None and is_pressed:
|
||||
# release previous key
|
||||
self.release(keyboard, self._prev_key)
|
||||
self._prev_key = key
|
||||
if is_pressed:
|
||||
keyboard.process_key(key.meta.mod, is_pressed)
|
||||
|
||||
self._active = True
|
||||
keyboard.process_key(key.meta.kc, is_pressed)
|
||||
|
||||
elif self._active:
|
||||
# release previous key if any other key is pressed
|
||||
if self._prev_key is not None:
|
||||
self.release(keyboard, self._prev_key)
|
||||
|
||||
return key
|
||||
|
||||
def before_hid_send(self, keyboard):
|
||||
return
|
||||
|
||||
def after_hid_send(self, keyboard):
|
||||
return
|
||||
|
||||
def on_powersave_enable(self, keyboard):
|
||||
return
|
||||
|
||||
def on_powersave_disable(self, keyboard):
|
||||
return
|
||||
|
||||
def after_matrix_scan(self, keyboard):
|
||||
return
|
||||
|
||||
def release(self, keyboard, key):
|
||||
keyboard.process_key(key.meta.mod, False)
|
||||
self._active = False
|
||||
self._prev_key = None
|
68
kmk/modules/sticky_mod.py
Normal file
68
kmk/modules/sticky_mod.py
Normal file
@ -0,0 +1,68 @@
|
||||
from kmk.keys import make_argumented_key
|
||||
from kmk.modules import Module
|
||||
|
||||
|
||||
class StickyModMeta:
|
||||
def __init__(self, kc, mod):
|
||||
self.kc = kc
|
||||
self.mod = mod
|
||||
|
||||
|
||||
class StickyMod(Module):
|
||||
def __init__(self):
|
||||
self._active = False
|
||||
self._active_key = None
|
||||
make_argumented_key(
|
||||
names=('SM',),
|
||||
validator=StickyModMeta,
|
||||
on_press=self.sm_pressed,
|
||||
on_release=self.sm_released,
|
||||
)
|
||||
|
||||
def during_bootup(self, keyboard):
|
||||
return
|
||||
|
||||
def before_matrix_scan(self, keyboard):
|
||||
return
|
||||
|
||||
def process_key(self, keyboard, key, is_pressed, int_coord):
|
||||
if self._active:
|
||||
# release previous key if any other key is pressed
|
||||
if self._active_key is not None:
|
||||
self.release_key(keyboard, self._active_key)
|
||||
|
||||
return key
|
||||
|
||||
def before_hid_send(self, keyboard):
|
||||
return
|
||||
|
||||
def after_hid_send(self, keyboard):
|
||||
return
|
||||
|
||||
def on_powersave_enable(self, keyboard):
|
||||
return
|
||||
|
||||
def on_powersave_disable(self, keyboard):
|
||||
return
|
||||
|
||||
def after_matrix_scan(self, keyboard):
|
||||
return
|
||||
|
||||
def release_key(self, keyboard, key):
|
||||
keyboard.process_key(key.meta.mod, False)
|
||||
self._active = False
|
||||
self._active_key = None
|
||||
|
||||
def sm_pressed(self, key, keyboard, *args, **kwargs):
|
||||
if self._active and self._active_key is not None:
|
||||
# release previous key
|
||||
self.release_key(keyboard, self._active_key)
|
||||
|
||||
keyboard.process_key(key.meta.mod, True)
|
||||
keyboard.process_key(key.meta.kc, True)
|
||||
self._active_key = key
|
||||
|
||||
def sm_released(self, key, keyboard, *args, **kwargs):
|
||||
keyboard.process_key(key.meta.kc, False)
|
||||
self._active_key = key
|
||||
self._active = True
|
@ -2,27 +2,27 @@ import unittest
|
||||
|
||||
from kmk.keys import KC
|
||||
from kmk.modules.layers import Layers
|
||||
from kmk.modules.modholdandtap import ModHoldAndTap
|
||||
from kmk.modules.sticky_mod import StickyMod
|
||||
from tests.keyboard_test import KeyboardTest
|
||||
|
||||
|
||||
class TestModHoldLayerTap(unittest.TestCase):
|
||||
class TestStickyMod(unittest.TestCase):
|
||||
def test_basic_kmk_keyboard(self):
|
||||
|
||||
keyboard = KeyboardTest(
|
||||
[Layers(), ModHoldAndTap()],
|
||||
[Layers(), StickyMod()],
|
||||
[
|
||||
[
|
||||
KC.A,
|
||||
KC.B,
|
||||
KC.MO(1),
|
||||
KC.LT(1, KC.C),
|
||||
KC.MHAT(kc=KC.TAB, mod=KC.LCTL(KC.LSFT)),
|
||||
KC.SM(kc=KC.TAB, mod=KC.LCTL(KC.LSFT)),
|
||||
KC.F,
|
||||
],
|
||||
[
|
||||
KC.MHAT(kc=KC.TAB, mod=KC.LGUI),
|
||||
KC.MHAT(kc=KC.TAB, mod=KC.LSFT(KC.LGUI)),
|
||||
KC.SM(kc=KC.TAB, mod=KC.LGUI),
|
||||
KC.SM(kc=KC.TAB, mod=KC.LSFT(KC.LGUI)),
|
||||
KC.TRNS,
|
||||
KC.B,
|
||||
KC.N5,
|
Loading…
Reference in New Issue
Block a user