Merge branch 'master' into topic-backspace-delete

This commit is contained in:
Kyle Brown 2019-03-12 00:25:05 -07:00 committed by GitHub
commit 7e06b143e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 89 additions and 33 deletions

View File

@ -230,23 +230,3 @@
|`KC.RALT(kc)`|Hold Right Alt and press `kc` | |`KC.RALT(kc)`|Hold Right Alt and press `kc` |
|`KC.RGUI(kc)`|Hold Right GUI and press `kc` | |`KC.RGUI(kc)`|Hold Right GUI and press `kc` |
## [Mod-Tap Keys] NOT IMPLEMENTED AT THIS TIME
|Key |Aliases |Description |
|------------|---------------------------------------|-------------------------------------------------------|
|`LCTL_T(kc)`|`CTL_T(kc)` |Left Control when held, `kc` when tapped |
|`RCTL_T(kc)`| |Right Control when held, `kc` when tapped |
|`LSFT_T(kc)`|`SFT_T(kc)` |Left Shift when held, `kc` when tapped |
|`RSFT_T(kc)`| |Right Shift when held, `kc` when tapped |
|`LALT_T(kc)`|`ALT_T(kc)` |Left Alt when held, `kc` when tapped |
|`RALT_T(kc)`|`ALGR_T(kc)` |Right Alt when held, `kc` when tapped |
|`LGUI_T(kc)`|`LCMD_T(kc)`, `RWIN_T(kc)`, `GUI_T(kc)`|Left GUI when held, `kc` when tapped |
|`RGUI_T(kc)`|`RCMD_T(kc)`, `RWIN_T(kc)` |Right GUI when held, `kc` when tapped |
|`C_S_T(kc)` | |Left Control and Shift when held, `kc` when tapped |
|`MEH_T(kc)` | |Left Control, Shift and Alt when held, `kc` when tapped|
|`LCAG_T(kc)`| |Left Control, Alt and GUI when held, `kc` when tapped |
|`RCAG_T(kc)`| |Right Control, Alt and GUI when held, `kc` when tapped |
|`ALL_T(kc)` | |Left Control, Shift, Alt and GUI when held, `kc` when tapped - more info [here](http://brettterpstra.com/2012/12/08/a-useful-caps-lock-key/)|
|`SGUI_T(kc)`|`SCMD_T(kc)`, `SWIN_T(kc)` |Left Shift and GUI when held, `kc` when tapped |
|`LCA_T(kc)` | |Left Control and Alt when held, `kc` when tapped |

30
docs/modtap.md Normal file
View File

@ -0,0 +1,30 @@
# ModTap
One key if you tap it, one or more modifiers if you hold it!
## Helpful examples
Just copy the example from New Keycode above your keymap and change KC.SOMETHING to the key that you want when tapped.
After that, just use the new keycode anywhere in your keymap.
|New Keycode | Description |
|-------------------------------------------------------|-----------------------------------------------------------------|
|LCTL = KC.MT(KC.SOMETHING, KC.LCTRL) |`LCTRL` if held `kc` if tapped |
|LSFT = KC.MT(KC.SOMETHING, KC.LSFT) |`LSHIFT` if held `kc` if tapped |
|LALT = KC.MT(KC.SOMETHING, KC.LALT) |`LALT` if held `kc` if tapped |
|LGUI = KC.MT(KC.SOMETHING, KC.LGUI) |`LGUI` if held `kc` if tapped |
|RCTL = KC.MT(KC.SOMETHING, KC.RCTRL) |`RCTRL` if held `kc` if tapped |
|RSFT = KC.MT(KC.SOMETHING, KC.RSFT) |`RSHIFT` if held `kc` if tapped |
|RALT = KC.MT(KC.SOMETHING, KC.RALT) |`RALT` if held `kc` if tapped |
|RGUI = KC.MT(KC.SOMETHING, KC.RGUI) |`RGUI` if held `kc` if tapped |
|SGUI = KC.MT(KC.SOMETHING, KC.LSHFT(KC.LGUI)) |`LSHIFT` and `LGUI` if held `kc` if tapped |
|LCA = KC.MT(KC.SOMETHING, KC.LCTRL(KC.LALT)) |`LCTRL` and `LALT` if held `kc` if tapped |
|LCAG = KC.MT(KC.SOMETHING, KC.LCTRL(KC.LALT(KC.LGUI))) |`LCTRL` and `LALT` and `LGUI` if held `kc` if tapped |
|MEH = KC.MT(KC.SOMETHING, KC.LCTRL(KC.LSFT(KC.LALT))) |`CTRL` and `LSHIFT` and `LALT` if held `kc` if tapped |
|HYPR = KC.MT(KC.SOMETHING, KC.HYPR) |`LCTRL` and `LSHIFT` and `LALT` and `LGUI` if held `kc` if tapped|
```python
SHFT_HOME = KC.MT(KC.HOME, KC.LSFT)
keyboard.keymap = [[ ...., SHFT_HOME, ....], ....]
```

View File

@ -22,9 +22,19 @@ import kmk.kmktime # isort:skip
import kmk.types # isort:skip import kmk.types # isort:skip
import kmk.util # isort:skip import kmk.util # isort:skip
import busio # isort:skip
import gc # isort:skip
import supervisor # isort:skip
from kmk.consts import LeaderMode, UnicodeMode # isort:skip
from kmk.hid import USB_HID # isort:skip
from kmk.internal_state import InternalState # isort:skip
from kmk.keys import KC # isort:skip
from kmk.matrix import MatrixScanner # isort:skip
# Now handlers that will be used in keys later # Now handlers that will be used in keys later
import kmk.handlers.layers import kmk.handlers.layers # isort:skip
import kmk.handlers.stock import kmk.handlers.stock # isort:skip
# Now stuff that depends on the above (and so on) # Now stuff that depends on the above (and so on)
import kmk.keys # isort:skip import kmk.keys # isort:skip
@ -39,16 +49,6 @@ import kmk.internal_state # isort:skip
# Thanks for sticking around. Now let's do real work, starting below # Thanks for sticking around. Now let's do real work, starting below
import busio
import gc
import supervisor
from kmk.consts import LeaderMode, UnicodeMode
from kmk.hid import USB_HID
from kmk.internal_state import InternalState
from kmk.keys import KC
from kmk.matrix import MatrixScanner
class Firmware: class Firmware:
debug_enabled = False debug_enabled = False

23
kmk/handlers/modtap.py Normal file
View File

@ -0,0 +1,23 @@
from kmk.kmktime import ticks_diff, ticks_ms
def mt_pressed(key, state, *args, **kwargs):
# Sets the timer start and acts like a modifier otherwise
state.keys_pressed.add(key.meta.mods)
state.start_time['mod_tap'] = ticks_ms()
return state
def mt_released(key, state, *args, **kwargs):
# On keyup, check timer, and press key if needed.
state.keys_pressed.discard(key.meta.mods)
timer_name = 'mod_tap'
if state.start_time[timer_name] and (
ticks_diff(ticks_ms(), state.start_time[timer_name]) < state.config.tap_time
):
state.hid_pending = True
state.tap_key(key.meta.kc)
state.start_time[timer_name] = None
return state

View File

@ -1,9 +1,10 @@
import gc import gc
import kmk.handlers.layers as layers import kmk.handlers.layers as layers
import kmk.handlers.modtap as modtap
import kmk.handlers.stock as handlers import kmk.handlers.stock as handlers
from kmk.consts import UnicodeMode from kmk.consts import UnicodeMode
from kmk.types import (AttrDict, KeySeqSleepMeta, LayerKeyMeta, from kmk.types import (AttrDict, KeySeqSleepMeta, LayerKeyMeta, ModTapKeyMeta,
TapDanceKeyMeta, UnicodeModeKeyMeta) TapDanceKeyMeta, UnicodeModeKeyMeta)
FIRST_KMK_INTERNAL_KEY = 1000 FIRST_KMK_INTERNAL_KEY = 1000
@ -679,6 +680,22 @@ make_argumented_key(
) )
def mod_tap_validator(kc, mods=None):
'''
Validates that mod tap keys are correctly used
'''
return ModTapKeyMeta(kc=kc, mods=mods)
# ModTap
make_argumented_key(
validator=mod_tap_validator,
names=('MT',),
on_press=modtap.mt_pressed,
on_release=modtap.mt_released,
)
gc.collect() gc.collect()

View File

@ -32,6 +32,12 @@ class LayerKeyMeta:
self.kc = kc self.kc = kc
class ModTapKeyMeta:
def __init__(self, kc=None, mods=None):
self.mods = mods
self.kc = kc
class KeySequenceMeta: class KeySequenceMeta:
def __init__(self, seq): def __init__(self, seq):
self.seq = seq self.seq = seq