Skip to main content

Inputronic Keyboard - Reading key events

Connections for this example

Connect the Inputronic Keyboard to your microcontroller via Qwiic/easyC cable or I²C pins as shown in the Getting Started guide.


Initialization

To use the Inputronic Keyboard, first import the required module, create the keyboard object, and initialize it:

from inputronic_keyboard import InputronicKeyboard

kbd = InputronicKeyboard()

if not kbd.begin():
print("Keyboard not found! Check connection.")
else:
print("Keyboard initialized successfully!")

kbd.begin()

Initializes the TCA8418 keypad controller, configuring the 8×10 matrix and I²C communication

Returns value: Boolean value. True if the keyboard was successfully initialized, False otherwise.


Reading Key Events

The keyboard uses a 10-event FIFO to store key presses and releases. To read events, first check if any are available, then read and decode them.

while kbd.eventsAvailable() > 0:
isRelease, row, col, label = kbd.readMappedEvent()

if not isRelease and label: # Only process key presses
print("Key pressed: {} (Row: {}, Col: {})".format(label, row, col))

kbd.eventsAvailable()

Returns the number of pending events in the FIFO

Returns value: Integer value representing the number of events (0-15)

kbd.readMappedEvent()

Reads one event from the FIFO and decodes it into row, column, and label

Returns value: Tuple: (isRelease, row, col, label) where isRelease is bool, row/col are integers (0-7, 0-9), and label is a string


Converting Labels to Characters

For printable keys, you can convert the label to a character. The module automatically handles SHIFT and CAPS behavior.

isRelease, row, col, label = kbd.readMappedEvent()

if not isRelease and label:
char = kbd.labelToChar(label, applyShift=True)
if char:
print("Character: {}".format(char))

kbd.labelToChar(label, applyShift)

Converts a single-character label to a printable character. Automatically applies SHIFT and CAPS logic.

Returns value: String containing a single character, or None if the label is not a printable character

Function parameters:

TypeNameDescription
strlabelKey label from the keymap
boolapplyShiftWhether to apply SHIFT transformations (default: True)

Checking Key State

You can check if a specific key is currently pressed:

if kbd.isKeyPressed("SHIFT"):
print("SHIFT is held down")

if kbd.isKeyPressed("A"):
print("A key is pressed")

kbd.isKeyPressed(label)

Checks if a specific key is currently being held down

Returns value: Boolean value: True if the key is pressed, False otherwise

Function parameters:

TypeNameDescription
strlabelKey label to check (e.g., 'SHIFT', 'A', 'ENTER')

Full Example

keyboard_poll.py

Polls the keyboard for key events and prints each key press with its label, row, and column to the console.