added docs

This commit is contained in:
Syed Hussaini 2022-04-09 15:02:49 -05:00 committed by Kyle Brown
parent c950785385
commit be308d516f
2 changed files with 47 additions and 20 deletions

27
docs/capsword.md Normal file
View File

@ -0,0 +1,27 @@
# CapsWord
The CapsWord module makes a key available that will function similar to caps lock but will deactive automatically when its encounters a key that breaks the word or after inactivity timeout.
By default it will not deactive capsword on numbers, alphabets, underscore, modifiers, minus, backspace and other keys like modtap, layers, etc
Add it to your keyboard's modules list with:
```python
from kmk.modules.capsword import CapsWord
# default inactivity timeout is 8s
caps_word=CapsWord()
# change inactivity timeout
# caps_word=CapsWord(timeout=5000)
# for no inactivity timeout
# caps_word=CapsWord(timeout=0)
# add additional ignored keys
# caps_word.keys_ignored.append(KC.COMMA)
keyboard.modules.append(caps_word)
keyboard.keymap = [
[
KC.CW,
],
]
```
## Keycodes
|Key |Aliases |Description |
|-----------------------|--------------------|-----------------------------------------------|
|`KC.CW` |`KC.CAPSWORD` |Enables/disables capsword |

View File

@ -1,4 +1,4 @@
from kmk.keys import KC, ModifierKey, make_key from kmk.keys import FIRST_KMK_INTERNAL_KEY, KC, ModifierKey, make_key
from kmk.modules import Module from kmk.modules import Module
@ -6,13 +6,13 @@ class CapsWord(Module):
# default timeout is 8000 # default timeout is 8000
# alphabets, numbers and few more keys will not disable capsword # alphabets, numbers and few more keys will not disable capsword
def __init__(self, timeout=8000): def __init__(self, timeout=8000):
self.alphabets = range(KC.A.code, KC.Z.code) self._alphabets = range(KC.A.code, KC.Z.code)
self.numbers = range(KC.N1.code, KC.N0.code) self._numbers = range(KC.N1.code, KC.N0.code)
self.keys_ignored = ( self.keys_ignored = [
KC.MINS, KC.MINS,
KC.BSPC, KC.BSPC,
KC.UNDS, KC.UNDS,
) ]
self._timeout_key = False self._timeout_key = False
self._cw_active = False self._cw_active = False
self.timeout = timeout self.timeout = timeout
@ -21,14 +21,12 @@ class CapsWord(Module):
'CAPSWORD', 'CAPSWORD',
'CW', 'CW',
), ),
on_press=self.cw_pressed,
) )
def during_bootup(self, keyboard): def during_bootup(self, keyboard):
return return
def matrix_detected_press(self, keyboard):
return keyboard.matrix_update is None
def before_matrix_scan(self, keyboard): def before_matrix_scan(self, keyboard):
return return
@ -36,14 +34,14 @@ class CapsWord(Module):
if self._cw_active and key != KC.CW: if self._cw_active and key != KC.CW:
continue_cw = False continue_cw = False
# capitalize alphabets # capitalize alphabets
if key.code in self.alphabets: if key.code in self._alphabets:
continue_cw = True continue_cw = True
keyboard.process_key(KC.LSFT, is_pressed) keyboard.process_key(KC.LSFT, is_pressed)
elif ( elif (
key.code in self.numbers key.code in self._numbers
or isinstance(key, ModifierKey) or isinstance(key, ModifierKey)
or key in self.keys_ignored or key in self.keys_ignored
or key.code >= 1000 # user defined keys are also ignored or key.code >= FIRST_KMK_INTERNAL_KEY # user defined keys are also ignored
): ):
continue_cw = True continue_cw = True
# requests and cancels existing timeouts # requests and cancels existing timeouts
@ -54,15 +52,6 @@ class CapsWord(Module):
else: else:
self.process_timeout() self.process_timeout()
# enables/disables capsword
if key == KC.CW and is_pressed:
if not self._cw_active:
self._cw_active = True
self.discard_timeout(keyboard)
self.request_timeout(keyboard)
else:
self.discard_timeout(keyboard)
self.process_timeout()
return key return key
def before_hid_send(self, keyboard): def before_hid_send(self, keyboard):
@ -96,3 +85,14 @@ class CapsWord(Module):
if self.timeout: if self.timeout:
keyboard.cancel_timeout(self._timeout_key) keyboard.cancel_timeout(self._timeout_key)
self._timeout_key = False self._timeout_key = False
def cw_pressed(self, key, keyboard, *args, **kwargs):
# enables/disables capsword
if key == KC.CW:
if not self._cw_active:
self._cw_active = True
self.discard_timeout(keyboard)
self.request_timeout(keyboard)
else:
self.discard_timeout(keyboard)
self.process_timeout()