Skip to content

Possible to end up with a NoneType for keyboard_layout #21

Closed
@caternuson

Description

@caternuson

Currently, the keyboard_layout member is only init'd if keyboard is None:

if self._keyboard is None:
self._keyboard = Keyboard(usb_hid.devices)
# This will need to be updated if we add more layouts. Currently there is only US.
self._keyboard_layout = KeyboardLayoutUS(self._keyboard)
return self._keyboard_layout

This can result in getting a None return if other calls have been done which initialize keyboard.

Example:

Adafruit CircuitPython 7.0.0-alpha.5 on 2021-07-21; Adafruit Macropad RP2040 with rp2040
>>> from adafruit_macropad import MacroPad
>>> macropad = MacroPad()
>>> macropad.keyboard.send(0x04)
>>> a
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'a' is not defined
>>> macropad.keyboard_layout.write("hello world")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'write'
>>> 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions