Closed Neradoc closed 3 years ago
I've pushed an update with a bunch more docs and rebased, and the type annotations.
It is the interior \n
that is disappearing:
with this change:
Adafruit CircuitPython 7.0.0-579-g9da541ed2-dirty on 2021-10-26; Adafruit CircuitPlayground Express with samd21g18
>>> from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
>>> from adafruit_hid.keyboard import Keyboard
>>> import usb_hid
>>> k = Keyboard(usb_hid.devices)
>>> l = KeyboardLayoutUS(k)
>>> l.write("abc\ndef\n")
>>> abcdef
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'abcdef' is not defined
>>>
Latest stock adafruit/main
:
Adafruit CircuitPython 7.0.0-579-g9da541ed2 on 2021-10-26; Adafruit CircuitPlayground Express with samd21g18
>>> from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
>>> from adafruit_hid.keyboard import Keyboard
>>> import usb_hid
>>> k = Keyboard(usb_hid.devices)
>>> l = KeyboardLayoutUS(k)
>>> l.write("abc\ndef\n")
>>> abc
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'abc' is not defined
>>> def
...
This is really odd. Now I cannot reproduce this.
This is really odd. Now I cannot reproduce this.
It's intermittent; still trying.
There's some kind of race condition, unrelated to this PR. I'm seeing this kind of thing intermittently, on both stock 7.0.0 and with this PR. So nothing to do with the PR.
>>> l.write("abc\ndeg\n")
>>> abcdeg
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'abcdeg' is not defined
>>> time.sleep(1);l.write("abc\ndeg\n")
>>> abc
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'abc' is not defined
>>> deg
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'deg' is not defined
>>>
This is the KeyboardLayoutBase class used in the layout bundle.
ord()
int value of high ascii and utf8 characters of one or more bytes to the keycode.Ñ
that can be accessed by typing first a dead key (like~
) followed by a regular key (likeN
) - on a Windows French keyboard for example.ord()
int values of each character.With the
Ñ
example:~
is altgr +é
,é
is keycode 0x1FN
is ascii code 0x4E, with the altgr bit becomes 0xCEÑ
is therefore0xD1: 0x1FCE,
ASCII_TO_KEYCODE[0x4E] == 0x91
(shift+0x11)write("Ñ")
sends the keycodes:(0xE6, 0x1F)
(altgr+é) then(0xE1, 0x11)
(shift+n)In the Keyboard Layout bundle, every layout class is called KeyboardLayout, to make changing layout easier without having a different class name in every file, and have to guess or lookup the class name (is it CamelCase of the module name ? Is it US or Us ?). For compatibility, I added
KeyboardLayout = KeyboardLayoutUS
in the US keyboard layout. Importing multiple layouts is possible by using the fullmodule.KeyboardLayout
name, orimport KeyboardLayout as ...
I'm not quite sure if I did the documentation correctly, I would love guidance on that. KeyboardLayoutBase is not for end-user use, but it's now the class that contains the method calls of the layout and therefore their documentation.