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).
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:
LV_PART_MAINThe main part. Uses the typical background style propertiesLV_PART_ITEMSThe buttons. Also uses the typical background style properties as well as text properties.
Usage
Modes
Keyboards have the following modes:
LV_KEYBOARD_MODE_TEXT_LOWERDisplay lower case lettersLV_KEYBOARD_MODE_TEXT_UPPERDisplay upper case lettersLV_KEYBOARD_MODE_SPECIALDisplay special charactersLV_KEYBOARD_MODE_NUMBERDisplay numbers, +/- sign, and decimal dotLV_KEYBOARD_MODE_USER_1throughLV_KEYBOARD_MODE_USER_4User-defined 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:
LV_SYMBOL_OKSendLV_EVENT_READYto the assigned Text Area.LV_SYMBOL_CLOSEorLV_SYMBOL_KEYBOARDSendLV_EVENT_CANCELto the assigned Text Area.LV_SYMBOL_BACKSPACEDelete character to the left.LV_SYMBOL_LEFTMove cursor left.LV_SYMBOL_RIGHTMove cursor right.LV_SYMBOL_NEW_LINENew line."ABC"Load upper-case map."abc"Load lower-case map."1#"Load number 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
LV_EVENT_VALUE_CHANGEDSent when the button is pressed/released or repeated after long press. The event data contains the ID of the pressed/released button.LV_EVENT_READY: The Ok button was clicked.LV_EVENT_CANCEL: The Close button was clicked.
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.
Keys
LV_KEY_RIGHT/UP/LEFT/RIGHTTo navigate among the buttons, selecting the one navigated to.LV_KEY_ENTERTo 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