Skip to content

touch_keypad

eventsys.touch_keypad

Optional eventsys mapper: on-screen cell-grid keypad over pointer events.

TouchKeypad is not a :class:~eventsys.KeypadDevice. It does not poll hardware or enqueue events. It subscribes to a :class:~eventsys.Runtime and maps primary-button pointer presses inside a rectangle into a grid of app key ids. Matching KEYDOWN / KEYUP values that appear in keys are tracked the same way.

Import explicitly (not loaded by import eventsys)::

from eventsys.touch_keypad import TouchKeypad

Callback idiom (canonical — runtime auto-service dispatches)::

from board_config import display_drv, runtime
from eventsys.touch_keypad import TouchKeypad

keys = [1, 2, 3, "A", "B", "C", "play", "pause", "esc"]
pad = TouchKeypad(
    runtime, 0, 0, display_drv.width, display_drv.height,
    cols=3, rows=3, keys=keys,
    on_press=lambda key: print("down", key),
    on_release=lambda key: print("up", key),
)
runtime.run_forever()

Poll idiom (legacy)::

pad = TouchKeypad(runtime, 0, 0, display_drv.width, display_drv.height,
                  cols=3, rows=3, keys=keys)
while True:
    runtime.poll()
    if pressed := pad.read():
        print(pressed)
    # Continuous movement: pad.read_held()

Classes

TouchKeypad

TouchKeypad(runtime, x, y, w, h, cols=3, rows=3, keys=None, translate=None, on_press=None, on_release=None)

Map a screen rectangle into a grid of app keys (pointer + optional keys).

Subscribes to MOUSEBUTTONDOWN / MOUSEBUTTONUP (button 1) and KEYDOWN / KEYUP on runtime. Grid cells use keys (default 0 .. cols*rows-1). Optional on_press / on_release fire from dispatch; read() / read_held() support poll loops.

Methods:
read
read()

Return keys pressed since the last read() (edge triggered).

read_held
read_held()

Return keys currently held down (level triggered).