---
title: "Input events"
canonical_url: https://developer.repebble.com/pebbleos/docs/samples/subsys/input/events/
last_updated: 2026-11-17
sdk_version: 4.44
---
# Input events

Source: https://developer.repebble.com/pebbleos/docs/samples/subsys/input/events/

This sample prints every event the input devices report for 30 seconds: keys pressed and released, touch axes and gestures. It registers a callback with `PBL_INPUT_CALLBACK_DEFINE()`, which drivers may call from an interrupt, so the callback only queues the event and the main thread prints it.

Run it on a board and press its keys or touch its screen while it listens; on the emulator nothing comes, and it reports 0 events.

Run:

`pbl samples samples/subsys/input/events`

Boards:

every board

## Sources

src/main.c

```
#include \<errno.h\>#include \<stdint.h\>#include \<stdio.h\>#include \<pbl/input/input.h\>#include \<pbl/kernel/msgq.h\>#include \<pbl/kernel/time.h\>#define LISTEN\_S 30#define QUEUE\_LEN 16/\* Input callbacks may run in an interrupt: they queue, the main thread prints. \*/static PBL\_MSGQ\_DEFINE(s\_events, sizeof(struct pbl\_input\_event), QUEUE\_LEN);static void prv\_input\_cb(const struct pbl\_input\_event \*evt, void \*user\_data) {(void)pbl\_msgq\_put(&s\_events, evt, PBL\_NO\_WAIT);}PBL\_INPUT\_CALLBACK\_DEFINE(prv\_input\_cb, nullptr);static void prv\_print(const struct pbl\_input\_event \*evt) {switch (evt-\>type) {case PBL\_INPUT\_EV\_KEY:printf("input: key %d %s\n", evt-\>code, evt-\>value != 0 ? "pressed" : "released");break;case PBL\_INPUT\_EV\_ABS:printf("input: axis %d = %d%s\n", evt-\>code, (int)evt-\>value, evt-\>sync ? ", sync" : "");break;case PBL\_INPUT\_EV\_GES:printf("input: gesture %d\n", evt-\>code);break;default:printf("input: type %d code %d value %d\n", evt-\>type, evt-\>code, (int)evt-\>value);break;}}int main(void) {uint64\_t end = pbl\_uptime\_ms() + LISTEN\_S \* 1000U;struct pbl\_input\_event evt;int count = 0;printf("input: printing events for %d s\n", LISTEN\_S);while (true) {uint64\_t now = pbl\_uptime\_ms();int ret;if (now \>= end) {break;}ret = pbl\_msgq\_get(&s\_events, &evt, PBL\_MSEC((uint32\_t)(end - now)));if (ret == -EAGAIN) {break;} else if (ret != 0) {fprintf(stderr, "input: no event (%d)\n", ret);return ret;}prv\_print(&evt);count++;}printf("input: %d events\n", count);printf("Sample done\n");return 0;}
```

## Output

```
input: printing events for 30 s
input: \d+ events
Sample done
```

Generated from PebbleOS [9e782207f](https://github.com/coredevices/pebbleos/commit/9e782207f53f8f1c02f7b13ea40cdc092d7bab3d). This page is maintained in the pebbleos repository: [docs/samples/subsys/input/events.md](https://github.com/coredevices/pebbleos/blob/9e782207f53f8f1c02f7b13ea40cdc092d7bab3d/docs/samples/subsys/input/events.md).
