Keypad and Keyboard¶
Overview¶
Full keyboards with all the letters or simple keypads with a few navigation buttons belong in the Keypad category.
You can fully control the user interface without a touchpad or mouse by using only a keypad. It works similarly to the TAB key on a PC to select an element in an application or web page.
Only widgets added to a group can be selected by a keyboard. Learn more at Groups.
Example¶
/*Create a group and add widgets to it so they can be selected by the keypad*/
lv_group_t * g = lv_group_create();
lv_indev_t * indev = lv_indev_create();
lv_indev_set_type(indev, LV_INDEV_TYPE_KEYPAD);
lv_indev_set_read_cb(indev, keyboard_read);
lv_indev_set_group(indev, g);
...
void keyboard_read(lv_indev_t * indev, lv_indev_data_t * data) {
if(key_pressed()) {
data->key = my_last_key(); /* Get the last pressed or released key */
data->state = LV_INDEV_STATE_PRESSED;
} else {
data->state = LV_INDEV_STATE_RELEASED;
}
}
Keys¶
There are some predefined keys which have special meaning:
LV_KEY_NEXT
: Move focus to the next objectLV_KEY_PREV
: Move focus to the previous objectLV_KEY_ENTER
: TriggersLV_EVENT_PRESSED
,LV_EVENT_CLICKED
, orLV_EVENT_LONG_PRESSED
eventsLV_KEY_UP
: Increase value or move upLV_KEY_DOWN
: Decrease value or move downLV_KEY_RIGHT
: Increase value or move to the rightLV_KEY_LEFT
: Decrease value or move to the leftLV_KEY_ESC
: Close or exit (e.g., close a Drop-Down List)LV_KEY_DEL
: Delete (e.g., a character on the right in a Text Area)LV_KEY_BACKSPACE
: Delete (e.g., a character on the left in a Text Area)LV_KEY_HOME
: Go to the beginning/top (e.g., in a Text Area)LV_KEY_END
: Go to the end (e.g., in a Text Area)
The most important special keys in your read_cb()
function are:
You should translate some of the read keys to these special keys to support navigation in a group and interact with selected widgets.