Keyboard (lv_keyboard)


The Keyboard object is a special Button matrix with predefined keymaps and other features to realize a virtual keyboard to write text.

Parts and Styles

Similarly to Button matices Keyboards consist of 2 part:

  • LV_KEYBOARD_PART_BG which is the main part and uses all the typical background properties

  • LV_KEYBOARD_PART_BTN which is virtual part for the buttons. It also uses all typical backround proeprties and the text properties.



The Keyboards have thefollowing modes:

  • LV_KEYBOARD_MODE_TEXT_LOWER - Display lower case letters

  • LV_KEYBOARD_MODE_TEXT_UPPER - Display upper case letters

  • LV_KEYBOARD_MODE_TEXT_SPECIAL - Display special characters

  • LV_KEYBOARD_MODE_NUM - Display numbers, +/- sign, and decimal dot.

The TEXT modes' layout contains buttons to change mode.

To set the mode manually, use lv_keyboard_set_mode(kb, mode). The default more is LV_KEYBOARD_MODE_TEXT_UPPER.

Assign Text area

You can assign a Text area to the Keyboard to automatically put the clicked characters there. To assign the text area, use lv_keyboard_set_textarea(kb, ta).

The assigned text area's cursor can be managed by the keyboard: when the keyboard is assigned, the previous text area's cursor will be hidden and the new one will be shown. When the keyboard is closed by the Ok or Close buttons, the cursor also will be hidden. The cursor manager feature is enabled by lv_keyboard_set_cursor_manage(kb, true). The default is not managed.

New Keymap

You can specify a new map (layout) for the keyboard with lv_keyboard_set_map(kb, map) and lv_keyboard_set_ctrl_map(kb, ctrl_map). Learn more about the Button matrix object. Keep in mind that, using following keywords will have the same effect as with the original map:

  • LV_SYMBOL_OK - Apply.

  • LV_SYMBOL_CLOSE - Close.

  • LV_SYMBOL_BACKSPACE - Delete on the left.

  • LV_SYMBOL_LEFT - Move the cursor left.

  • LV_SYMBOL_RIGHT - Move the cursor right.

  • "ABC" - Load the uppercase map.

  • "abc" - Load the lower case map.

  • "Enter" - New line.


Besides the Generic events, the following Special events are sent by the keyboards:

  • LV_EVENT_VALUE_CHANGED - Sent when the button is pressed/released or repeated after long press. The event data is set to the ID of the pressed/released button.

  • LV_EVENT_APPLY - The Ok button is clicked.

  • LV_EVENT_CANCEL - The Close button is clicked.

The keyboard has a default event handler callback called lv_keyboard_def_event_cb. It handles the button pressing, map changing, the assigned text area, etc. You can completely replace it with your custom event handler however, you can call lv_keyboard_def_event_cb at the beginning of your event handler to handle the same things as before.

Learn more about Events.


The following Keys are processed by the buttons:

  • LV_KEY_RIGHT/UP/LEFT/RIGHT - To navigate among the buttons and select one.

  • LV_KEY_ENTER - To press/release the selected button.

Learn more about Keys.



Keyboard with text area


#include "../../../lv_examples.h"

void lv_ex_keyboard_1(void)
    /*Create a keyboard and apply the styles*/
    lv_obj_t *kb = lv_keyboard_create(lv_scr_act(), NULL);
    lv_keyboard_set_cursor_manage(kb, true);

    /*Create a text area. The keyboard will write here*/
    lv_obj_t *ta = lv_textarea_create(lv_scr_act(), NULL);
    lv_obj_align(ta, NULL, LV_ALIGN_IN_TOP_MID, 0, LV_DPI / 16);
    lv_textarea_set_text(ta, "");
    lv_coord_t max_h = LV_VER_RES / 2 - LV_DPI / 8;
    if(lv_obj_get_height(ta) > max_h) lv_obj_set_height(ta, max_h);

    /*Assign the text area to the keyboard*/
    lv_keyboard_set_textarea(kb, ta);


Keyboard with text area

No examples yet.



typedef uint8_t lv_keyboard_mode_t
typedef uint8_t lv_keyboard_style_t


enum [anonymous]

Current keyboard mode.


enum [anonymous]




lv_obj_t *lv_keyboard_create(lv_obj_t *par, const lv_obj_t *copy)

Create a keyboard objects


pointer to the created keyboard

  • par: pointer to an object, it will be the parent of the new keyboard

  • copy: pointer to a keyboard object, if not NULL then the new object will be copied from it

void lv_keyboard_set_textarea(lv_obj_t *kb, lv_obj_t *ta)

Assign a Text Area to the Keyboard. The pressed characters will be put there.

  • kb: pointer to a Keyboard object

  • ta: pointer to a Text Area object to write there

void lv_keyboard_set_mode(lv_obj_t *kb, lv_keyboard_mode_t mode)

Set a new a mode (text or number map)

  • kb: pointer to a Keyboard object

  • mode: the mode from 'lv_keyboard_mode_t'

void lv_keyboard_set_cursor_manage(lv_obj_t *kb, bool en)

Automatically hide or show the cursor of the current Text Area

  • kb: pointer to a Keyboard object

  • en: true: show cursor on the current text area, false: hide cursor

void lv_keyboard_set_map(lv_obj_t *kb, lv_keyboard_mode_t mode, const char *map[])

Set a new map for the keyboard

  • kb: pointer to a Keyboard object

  • mode: keyboard map to alter 'lv_keyboard_mode_t'

  • map: pointer to a string array to describe the map. See 'lv_btnmatrix_set_map()' for more info.

void lv_keyboard_set_ctrl_map(lv_obj_t *kb, lv_keyboard_mode_t mode, const lv_btnmatrix_ctrl_t ctrl_map[])

Set the button control map (hidden, disabled etc.) for the keyboard. The control map array will be copied and so may be deallocated after this function returns.

  • kb: pointer to a keyboard object

  • mode: keyboard ctrl map to alter 'lv_keyboard_mode_t'

  • ctrl_map: pointer to an array of lv_btn_ctrl_t control bytes. See: lv_btnmatrix_set_ctrl_map for more details.

lv_obj_t *lv_keyboard_get_textarea(const lv_obj_t *kb)

Assign a Text Area to the Keyboard. The pressed characters will be put there.


pointer to the assigned Text Area object

  • kb: pointer to a Keyboard object

lv_keyboard_mode_t lv_keyboard_get_mode(const lv_obj_t *kb)

Set a new a mode (text or number map)


the current mode from 'lv_keyboard_mode_t'

  • kb: pointer to a Keyboard object

bool lv_keyboard_get_cursor_manage(const lv_obj_t *kb)

Get the current cursor manage mode.


true: show cursor on the current text area, false: hide cursor

  • kb: pointer to a Keyboard object

const char **lv_keyboard_get_map_array(const lv_obj_t *kb)

Get the current map of a keyboard


the current map

  • kb: pointer to a keyboard object

void lv_keyboard_def_event_cb(lv_obj_t *kb, lv_event_t event)

Default keyboard event to add characters to the Text area and change the map. If a custom event_cb is added to the keyboard this function be called from it to handle the button clicks

  • kb: pointer to a keyboard

  • event: the triggering event

struct lv_keyboard_ext_t

Public Members

lv_btnmatrix_ext_t btnm
lv_obj_t *ta
lv_keyboard_mode_t mode
uint8_t cursor_mng