Skip to content

Commit de7025f

Browse files
committed
fix and add dosctrings to the properties
1 parent d8e2445 commit de7025f

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

adafruit_hid/keyboard_layout_base.py

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,34 @@ class KeyboardLayoutBase:
2121
Non-supported characters and most control characters will raise an exception.
2222
"""
2323

24-
# We use the top bit of each byte (0x80) to indicate
25-
# that the shift key should be pressed
2624
SHIFT_FLAG = 0x80
25+
"""Bit set in any keycode byte if the shift key is required for the character."""
2726
ALTGR_FLAG = 0x80
27+
"""Bit set in the combined keys table if altgr is required for the first key."""
2828
SHIFT_CODE = 0xE1
29+
"""The SHIFT keycode, to avoid dependency to the Keycode class."""
2930
RIGHT_ALT_CODE = 0xE6
31+
"""The ALTGR keycode, to avoid dependency to the Keycode class."""
3032
ASCII_TO_KEYCODE = ()
31-
NEED_ALTGR = ""
33+
"""Bytes string of keycodes for low ASCII characters, indexed by the ASCII value. Keycodes use the `SHIFT_FLAG` if needed. Dead keys are excluded by assigning the keycode 0."""
3234
HIGHER_ASCII = {}
35+
"""Dictionary that associates the ord() int value of high ascii and utf8 characters
36+
to their keycode. Keycodes use the `SHIFT_FLAG` if needed."""
37+
NEED_ALTGR = ""
38+
"""Characters in `ASCII_TO_KEYCODE` and `HIGHER_ASCII` that need the ALTGR key pressed to type."""
3339
COMBINED_KEYS = {}
40+
"""
41+
Dictionary of characters (indexed by ord() value) that can be accessed by typing first
42+
a dead key followed by a regular key, like ``ñ`` as ``~ + n``. The value is a 2-bytes int:
43+
the high byte is the dead-key keycode (including SHIFT_FLAG), the low byte is the ascii code
44+
of the second character, with ALTGR_FLAG set if the dead key (the first key) needs ALTGR.
45+
46+
The combined-key codes bits are: ``0b SDDD DDDD AKKK KKKK``:
47+
``S`` is the shift flag for the **first** key,
48+
``DDD DDDD`` is the keycode for the **first** key,
49+
``A`` is the altgr flag for the **first** key,
50+
``KKK KKKK`` is the (low) ASCII code for the second character.
51+
"""
3452

3553
def __init__(self, keyboard):
3654
"""Specify the layout for the given keyboard.
@@ -63,7 +81,7 @@ def _write(self, keycode, altgr=False):
6381
def write(self, string):
6482
"""Type the string by pressing and releasing keys on my keyboard.
6583
66-
:param string: A string of ASCII characters.
84+
:param string: A string of UTF-8 characters to convert to key presses and send.
6785
:raises ValueError: if any of the characters has no keycode
6886
(such as some control characters).
6987
@@ -132,11 +150,11 @@ def keycodes(self, char):
132150
return codes
133151

134152
def _above128char_to_keycode(self, char):
135-
"""Return keycode for above 128 ascii codes.
153+
"""Return keycode for above 128 utf8 codes.
136154
137155
A character can be indexed by the char itself or its int ord() value.
138156
139-
:param char_val: ascii char value
157+
:param char_val: char value
140158
:return: keycode, with modifiers if needed
141159
"""
142160
if ord(char) in self.HIGHER_ASCII:
@@ -146,7 +164,7 @@ def _above128char_to_keycode(self, char):
146164
return 0
147165

148166
def _char_to_keycode(self, char):
149-
"""Return the HID keycode for the given ASCII character, with the SHIFT_FLAG possibly set.
167+
"""Return the HID keycode for the given character, with the SHIFT_FLAG possibly set.
150168
151169
If the character requires pressing the Shift key, the SHIFT_FLAG bit is set.
152170
You must clear this bit before passing the keycode in a USB report.

0 commit comments

Comments
 (0)