implement keyboard lock status reader API
This commit is contained in:
parent
a62d39a252
commit
8419ed789c
@ -9,6 +9,7 @@ extensions are
|
|||||||
|
|
||||||
- [International](international.md): Adds international keycodes
|
- [International](international.md): Adds international keycodes
|
||||||
- [LED](led.md): Adds backlight support. This is for monocolor backlight, not RGB
|
- [LED](led.md): Adds backlight support. This is for monocolor backlight, not RGB
|
||||||
|
- [LockStatus](lock_status.md): Exposes host-side locks like caps or num lock.
|
||||||
- [MediaKeys](media_keys.md): Adds support for media keys such as volume
|
- [MediaKeys](media_keys.md): Adds support for media keys such as volume
|
||||||
- [RGB](rgb.md): RGB lighting for underglow. Will work on most matrix RGB as will
|
- [RGB](rgb.md): RGB lighting for underglow. Will work on most matrix RGB as will
|
||||||
be treated the same as underglow.
|
be treated the same as underglow.
|
||||||
|
23
docs/lock_status.md
Normal file
23
docs/lock_status.md
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
# Lock Status
|
||||||
|
This extension exposes host-side locks like caps or num lock.
|
||||||
|
|
||||||
|
## Enabling the extension
|
||||||
|
```python
|
||||||
|
from kmk.extensions.lock_status import LockStatus
|
||||||
|
|
||||||
|
locks = LockStatus()
|
||||||
|
keyboard.extensions.append(locks)
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## Read Lock Status
|
||||||
|
Lock states can be retrieved with getter methods and are truth valued -- `True`
|
||||||
|
when the lock is enabled and `False` otherwise.
|
||||||
|
|
||||||
|
|Method |Description |
|
||||||
|
|--------------------------|------------|
|
||||||
|
|`locks.get_caps_lock() ` |Num Lock |
|
||||||
|
|`locks.get_caps_lock() ` |Caps Lock |
|
||||||
|
|`locks.get_scroll_lock() `|Scroll Lock |
|
||||||
|
|`locks.get_compose() ` |Compose |
|
||||||
|
|`locks.get_kana() ` |Kana |
|
64
kmk/extensions/lock_status.py
Normal file
64
kmk/extensions/lock_status.py
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
import usb_hid
|
||||||
|
|
||||||
|
from kmk.extensions import Extension
|
||||||
|
from kmk.hid import HIDUsage
|
||||||
|
|
||||||
|
|
||||||
|
class LockCode:
|
||||||
|
NUMLOCK = 0x01
|
||||||
|
CAPSLOCK = 0x02
|
||||||
|
SCROLLLOCK = 0x04
|
||||||
|
COMPOSE = 0x08
|
||||||
|
KANA = 0x10
|
||||||
|
RESERVED = 0x20
|
||||||
|
|
||||||
|
|
||||||
|
class LockStatus(Extension):
|
||||||
|
def __init__(self):
|
||||||
|
self.report = 0x00
|
||||||
|
self.hid = None
|
||||||
|
for device in usb_hid.devices:
|
||||||
|
if device.usage == HIDUsage.KEYBOARD:
|
||||||
|
self.hid = device
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return ('LockStatus(report={})').format(self.report)
|
||||||
|
|
||||||
|
def during_bootup(self, sandbox):
|
||||||
|
return
|
||||||
|
|
||||||
|
def before_matrix_scan(self, sandbox):
|
||||||
|
return
|
||||||
|
|
||||||
|
def after_matrix_scan(self, sandbox):
|
||||||
|
return
|
||||||
|
|
||||||
|
def before_hid_send(self, sandbox):
|
||||||
|
return
|
||||||
|
|
||||||
|
def after_hid_send(self, sandbox):
|
||||||
|
report = self.hid.get_last_received_report()
|
||||||
|
if report[0] != self.report:
|
||||||
|
self.report = report[0]
|
||||||
|
return
|
||||||
|
|
||||||
|
def on_powersave_enable(self, sandbox):
|
||||||
|
return
|
||||||
|
|
||||||
|
def on_powersave_disable(self, sandbox):
|
||||||
|
return
|
||||||
|
|
||||||
|
def get_num_lock(self):
|
||||||
|
return bool(self.report & LockCode.NUMLOCK)
|
||||||
|
|
||||||
|
def get_caps_lock(self):
|
||||||
|
return bool(self.report & LockCode.CAPSLOCK)
|
||||||
|
|
||||||
|
def get_scroll_lock(self):
|
||||||
|
return bool(self.report & LockCode.SCROLLLOCK)
|
||||||
|
|
||||||
|
def get_compose(self):
|
||||||
|
return bool(self.report & LockCode.COMPOSE)
|
||||||
|
|
||||||
|
def get_kana(self):
|
||||||
|
return bool(self.report & LockCode.KANA)
|
Loading…
x
Reference in New Issue
Block a user