Physical keyboard and trackball input handling
Reads input from the T-Deck's QWERTY keyboard and trackball. Supports key events with modifiers (shift, ctrl, alt, fn), special keys (arrows, enter, escape), and trackball movement/click. The keyboard is polled during the main loop; use read() to get pending key events.
if ez.keyboard.available() then
local key = ez.keyboard.read()
if key.character then
print("Pressed:", key.character)
elseif key.special then
print("Special key:", key.special)
end
end
local level = ez.keyboard.get_backlight()
print("Backlight:", level)
print("Keyboard mode:", ez.keyboard.get_mode())
print(ez.keyboard.get_pin_states())
-- Output: "KB_INT=0 TB_UP=0 TB_DOWN=0 TB_LEFT=0 TB_RIGHT=0 TB_CLICK=0"
local bits = ez.keyboard.get_raw_matrix_bits()
if bits ~= 0 then
print("Some keys are pressed")
end
print("Repeat delay:", ez.keyboard.get_repeat_delay(), "ms")
if ez.keyboard.get_repeat_enabled() then
print("Key repeat is on")
end
print("Repeat rate:", ez.keyboard.get_repeat_rate(), "ms")
print("Trackball mode:", ez.keyboard.get_trackball_mode())
local sens = ez.keyboard.get_trackball_sensitivity()
print("Trackball sensitivity:", sens)
-- Quick check before reading keys
if ez.keyboard.has_key_activity() then
local key = ez.keyboard.read()
end
if ez.keyboard.has_trackball() then
print("Use trackball to navigate")
else
print("Use arrow keys to navigate")
end
if ez.keyboard.is_alt_held() then
print("Alt is held")
end
if ez.keyboard.is_ctrl_held() then
print("Ctrl is held")
end
if ez.keyboard.is_fn_held() then
print("Fn is held - function layer active")
end
| Parameter | Description |
|---|---|
| char | Single-character string |
if ez.keyboard.is_held("w") then move_forward() end
| Parameter | Description |
|---|---|
| col | Column index (0-4) |
| row | Row index (0-6) |
-- Check if specific matrix position is pressed
if ez.keyboard.is_key_pressed(2, 3) then
print("Key at col 2, row 3 is pressed")
end
if ez.keyboard.is_shift_held() then
print("Shift is held")
end
local key = ez.keyboard.read()
if key then
if key.special == "ENTER" then
submit_form()
elseif key.character and key.ctrl then
-- Ctrl+key shortcut
handle_shortcut(key.character)
end
end
| Parameter | Description |
|---|---|
| timeout_ms | Timeout in milliseconds (0 = wait forever) |
print("Press any key to continue...")
local key = ez.keyboard.read_blocking(5000) -- Wait up to 5 seconds
if key then
print("You pressed a key!")
else
print("Timeout - no key pressed")
end
local code = ez.keyboard.read_raw_code()
if code then
print("Raw key code:", string.format("0x%02X", code))
end
ez.keyboard.set_mode("raw")
local matrix = ez.keyboard.read_raw_matrix()
if matrix then
for col, val in ipairs(matrix) do
print("Column", col, "=", string.format("0x%02X", val))
end
end
| Parameter | Description |
|---|---|
| level | Brightness level (0-255, 0 = off, 255 = max) |
ez.keyboard.set_backlight(128) -- Half brightness
ez.keyboard.set_backlight(0) -- Turn off to save battery
| Parameter | Description |
|---|---|
| mode | "normal" for translated keys, "raw" for matrix access |
ez.keyboard.set_mode("raw")
local matrix = ez.keyboard.read_raw_matrix()
ez.keyboard.set_mode("normal")
| Parameter | Description |
|---|---|
| delay_ms | Delay in milliseconds (50-2000, default 400) |
ez.keyboard.set_repeat_delay(300) -- Faster repeat start
| Parameter | Description |
|---|---|
| enabled | true to enable, false to disable |
ez.keyboard.set_repeat_enabled(false) -- Single press only
| Parameter | Description |
|---|---|
| rate_ms | Interval in milliseconds (10-500, default 50) |
ez.keyboard.set_repeat_rate(30) -- Faster repeat
| Parameter | Description |
|---|---|
| mode | "polling" or "interrupt" |
ez.keyboard.set_trackball_mode("interrupt") -- Lower latency
| Parameter | Description |
|---|---|
| value | Sensitivity value (1-10, higher = more sensitive) |
ez.keyboard.set_trackball_sensitivity(3) -- Slightly faster