cardputer-adv-keyboard 0.1.0

Rust library implementing an easy to use interface for getting keyboard input on the Cardputer-Adv
Documentation

Cardputer-Adv keyboard

Crates.io docs.rs CI License

A keyboard driver for the M5Stack Cardputer-Adv, built on top of the tca8418 driver. Handles press/release events, shift/Fn layer resolution and modifier tracking.

Getting started

use cardputer_adv_keyboard::Keyboard;

let mut keyboard = Keyboard::new(i2c);
keyboard.init().unwrap();

Usage

If you are only interested in inputs, use .inputs() to get the resolved inputs of the current key presses in the buffer.

These are what the key press produces, not which physical key was pressed. This means pressing Aa + G maps to an uppercase G whereas pressing just G maps to a lowercase g. Pressing Fn + ; maps to an up arrow, etc.

In short: What you see on the keyboard is what you get.

Here is a simple example on how to capture user input:

use cardputer_adv_keyboard::KeyInput;

for input in keyboard.inputs().unwrap() {
    match input {
        KeyInput::Char(c) => { /* handle character input */ }
        KeyInput::Backspace => { /* handle backspace */ }
        KeyInput::Enter => { /* handle enter */ }
        _ => {}
    }
}

Advanced usage

If you are interested in the raw key press and release events, you can use .events() which returns full KeyboardEvents with physical key identity, press/release state, and a current modifiers:

This allows you to track when a key is released or define custom Modifier + Key combinations

use cardputer_adv_keyboard::PhysicalKey;

for event in keyboard.events().unwrap() {
    match (event.physical_key, event.modifiers.ctrl) {
        (PhysicalKey::C, true) => { /* handle Ctrl+C */ }
        _ => {}
    }
}

See the docs for more details.