Keyboard (lv_keyboard)

The Keyboard Widget is a special Button Matrix (lv_buttonmatrix) with predefined keymaps and other features to provide an on-screen virtual keyboard to write text into a Text Area (lv_textarea).

Edit on GitHub

Overview

The Keyboard Widget is a special Button Matrix (lv_buttonmatrix) with predefined keymaps and other features to provide an on-screen virtual keyboard to write text into a Text Area (lv_textarea).

Parts and Styles

Similar to Button Matrix, the Keyboard Widget consists of 2 parts:

Usage

Modes

Keyboards have the following modes:

The layouts of the TEXT modes contain "keys" to change mode.

To set the mode programmatically, use lv_keyboard_set_mode(kb, mode). The default mode 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, text_area).

Key Pop-Overs

To enable key pop-overs on press, like on common Android and iOS keyboards, use lv_keyboard_set_popovers(kb, true). Default control maps are preconfigured to only show the pop-overs on keys that produce a symbol (i.e. not on space). If you use a custom keymap (see below), set the LV_BUTTONMATRIX_CTRL_POPOVER flag for each key for which a pop-over should be shown.

Note that pop-overs for keys in the top row will draw outside the Widget boundaries. To account for this, reserve extra free space on top of the Keyboard or ensure that the Keyboard is added after any Widgets adjacent to its top boundary (placing it "above" those Widgets) so that pop-overs will be drawn over them.

Pop-overs currently are merely a visual effect and don't allow selecting additional characters such as accented characters yet.

New Keymap

You can specify a new map (layout) for the Keyboard with lv_keyboard_set_map(kb, LV_KEYBOARD_MODE_..., kb_map, kb_ctrl). See Button Matrix's Button map section for more information about creating new maps.

Keep in mind that using following keywords in the map will have the same effect as with the original map:

Key customization

Each key can be customized by using draw events such as LV_EVENT_DRAW_TASK_ADDED.

Check out the examples to see how it can be used in the practice.

Events

The Keyboard has a default event handler callback called lv_keyboard_def_event_cb, which handles the button pressing, map changing, sending events to the assigned text area, etc. You can remove it and replace it with a custom event handler if you wish, or add an additional call-back of your own.

In LVGL v8.0 and newer, adding an event handler to the Keyboard does not remove the default event handler. This behavior differs from v7, where adding an event handler would replace the previous one.

Further Reading

Learn more about Events emitted by all Widgets.

Learn more about events.

Keys

  • LV_KEY_RIGHT/UP/LEFT/RIGHT To navigate among the buttons, selecting the one navigated to.
  • LV_KEY_ENTER To press/release the selected button.

Further Reading

Learn more about Keys.

Examples

Keyboard with text area

Keyboard with custom map

Keyboard with drawing

API

How is this guide?

Last updated on

On this page