---
title: "LVGL: Input"
canonical_url: https://developer.repebble.com/pebbleos/docs/samples/third_party/lvgl/input/
last_updated: 2026-11-21
sdk_version: 4.44
---
# LVGL: Input

Source: https://developer.repebble.com/pebbleos/docs/samples/third_party/lvgl/input/

This sample puts a counter and two buttons on the display and lets them be used for 30 seconds, with what the board has: Up and Down move the focus between the buttons and Select clicks the focused one, and a touch clicks the one under the finger. Each click runs the event callback of the button, which updates the label and prints the count.

The keys reach [LVGL](https://developer.repebble.com/pebbleos/docs/third_party/lvgl.md) with `CONFIG_INPUT`, and the touchscreen with `CONFIG_TOUCH`, which the sample sets in `boards/<board>.conf` for the boards that have one.

On the emulator, click the buttons in its window or use the arrow keys; nothing comes when run by `pbl samples`, and it reports 0 clicks.

Run:

`pbl samples samples/third_party/lvgl/input`

Boards:

every board

## Sources

src/main.c

```
#include \<stdio.h\>#include \<pbl/kernel/delay.h\>#include \<pbl/kernel/time.h\>#include \<pbl\_lvgl.h\>#define LISTEN\_S 30static lv\_obj\_t \*s\_label;static int s\_count;static int s\_clicks;/\* Runs from lv\_timer\_handler(), on the thread that calls it. \*/static void prv\_clicked(lv\_event\_t \*e) {s\_count += (int)(intptr\_t)lv\_event\_get\_user\_data(e);s\_clicks++;lv\_label\_set\_text\_fmt(s\_label, "%d", s\_count);printf("lvgl: count %d\n", s\_count);}static void prv\_add\_button(lv\_obj\_t \*parent, const char \*text, int step) {lv\_obj\_t \*button = lv\_button\_create(parent);lv\_obj\_t \*label = lv\_label\_create(button);lv\_obj\_set\_size(button, 56, 44);lv\_obj\_add\_event\_cb(button, prv\_clicked, LV\_EVENT\_CLICKED, (void \*)(intptr\_t)step);lv\_label\_set\_text(label, text);lv\_obj\_center(label);}int main(void) {lv\_obj\_t \*row;uint64\_t end;int ret;ret = pbl\_lvgl\_init();if (ret != 0) {fprintf(stderr, "lvgl: init failed (%d)\n", ret);return ret;}printf("lvgl: keypad: %s, pointer: %s\n", pbl\_lvgl\_get\_keypad() != nullptr ? "yes" : "no",pbl\_lvgl\_get\_pointer() != nullptr ? "yes" : "no");s\_label = lv\_label\_create(lv\_screen\_active());lv\_label\_set\_text(s\_label, "0");lv\_obj\_align(s\_label, LV\_ALIGN\_CENTER, 0, -45);row = lv\_obj\_create(lv\_screen\_active());lv\_obj\_remove\_style\_all(row);lv\_obj\_set\_size(row, LV\_SIZE\_CONTENT, LV\_SIZE\_CONTENT);lv\_obj\_set\_flex\_flow(row, LV\_FLEX\_FLOW\_ROW);lv\_obj\_set\_style\_pad\_column(row, 12, 0);/\* Room for the outline a theme may draw around the focused button. \*/lv\_obj\_set\_style\_pad\_all(row, 4, 0);lv\_obj\_align(row, LV\_ALIGN\_CENTER, 0, 20);/\* \* Widgets that take input join the default group as they are created: Up and Down move the \* focus between them and Select clicks the focused one, as a touch does on any of them. \*/prv\_add\_button(row, LV\_SYMBOL\_MINUS, -1);prv\_add\_button(row, LV\_SYMBOL\_PLUS, 1);printf("lvgl: listening for %d s\n", LISTEN\_S);end = pbl\_uptime\_ms() + LISTEN\_S \* 1000U;while (pbl\_uptime\_ms() \< end) {pbl\_sleep\_ms(lv\_timer\_handler());}printf("lvgl: %d clicks\n", s\_clicks);printf("Sample done\n");return 0;}
```

## Output

```
lvgl: keypad: yes, pointer: (yes|no)
lvgl: listening for 30 s
lvgl: \d+ clicks
Sample done
```

Generated from PebbleOS [4bbc630fa](https://github.com/coredevices/pebbleos/commit/4bbc630fa451369e352c06b8276c7fe37c67f4fd). This page is maintained in the pebbleos repository: [docs/samples/third\_party/lvgl/input.md](https://github.com/coredevices/pebbleos/blob/4bbc630fa451369e352c06b8276c7fe37c67f4fd/docs/samples/third_party/lvgl/input.md).
