Skip to content

graphics/input: Add getevent input event monitor tool#3434

Open
HongChao6 wants to merge 1 commit intoapache:masterfrom
HongChao6:getevent
Open

graphics/input: Add getevent input event monitor tool#3434
HongChao6 wants to merge 1 commit intoapache:masterfrom
HongChao6:getevent

Conversation

@HongChao6
Copy link
Copy Markdown

@HongChao6 HongChao6 commented Mar 25, 2026

Summary

Add getevent, a command-line input event monitor that captures and displays real-time events from input devices.

What

getevent captures and displays real-time input events from mouse, touchscreen, and keyboard devices. It reads from input device nodes (/dev/mouse*, /dev/input*, /dev/kbd*) using non-blocking I/O with poll(), and prints structured event data via syslog.

Supported event types:

  • Mouse: button state, x/y coordinates, wheel (if enabled)
  • Touchscreen: multi-touch points with coordinates, flags, timestamps, and optional pressure/size detail
  • Keyboard: key code and event type

When / Why

This tool is useful during:

  • Driver bring-up: verify that a newly ported input driver produces correct events
  • Input debugging: inspect raw event data to diagnose issues like missed touches, incorrect coordinates, or stuck keys
  • System integration: confirm that input devices are properly registered and accessible from userspace

Without getevent, developers must write ad-hoc test programs or read device nodes manually to verify input behavior. This tool provides a ready-made, consistent way to do so.

Usage

# Auto-detect all input devices in /dev
getevent

# Monitor a specific mouse device
getevent -m /dev/mouse0

# Monitor a specific touchscreen
getevent -t /dev/input0

# Monitor a specific keyboard
getevent -k /dev/kbd0

# Combine multiple devices
getevent -m /dev/mouse0 -t /dev/input0 -k /dev/kbd0

Press Ctrl+C to stop.

Configuration

CONFIG_GRAPHICS_INPUT_GETEVENT=y            # Enable getevent
CONFIG_GRAPHICS_INPUT_GETEVENT_DETAIL_INFO=y # Optional: show touch pressure/size

Impact

  • Is new feature added? Is existing feature changed? YES - New getevent command-line tool added under graphics/input/.
  • Impact on user (will user need to adapt to change)? NO - This is a new optional tool, no existing functionality is changed.
  • Impact on build (will build process change)? NO - Only builds when CONFIG_GRAPHICS_INPUT_GETEVENT is explicitly enabled.
  • Impact on hardware (will arch(s) / board(s) / driver(s) change)? NO - No driver or architecture changes, reads existing input device nodes only.
  • Impact on documentation (is update required / provided)? YES - Documentation PR submitted: Documentation: Add getevent input event monitor documentation. nuttx#18615
  • Impact on security (any sort of implications)? NO
  • Impact on compatibility (backward/forward/interoperability)? NO - Purely additive, no existing code is modified (except adding getevent entry to Make.defs and Makefile).

Testing

I confirm that changes are verified on local setup and works as intended:

  • Build Host(s): Ubuntu 22.04.5 LTS, x86_64, GCC 13.4.0
  • Target(s): arm

Testing logs (runtime):

[getevent]: opening /dev/input0
[getevent]: ioctl TSIOC_GETMAXPOINTS: 1
[getevent]: opening /dev/kbd0
[getevent]: opening /dev/mouse0

[getevent]: touch event: /dev/input0
[getevent]:    npoints : 1
[getevent]: Point      : 0
[getevent]:      flags : 11
[getevent]:          x : 493
[getevent]:          y : 312
[getevent]:  timestamp : 31272800

[getevent]: keyboard event: /dev/kbd0
[getevent]:          type : 0 
[getevent]:          code : 57
[getevent]: keyboard event: /dev/kbd0
[getevent]:          type : 1
[getevent]:          code : 57

[getevent]: mouse event: /dev/mouse0
[getevent]:    buttons : 00
[getevent]:          x : 14
[getevent]:          y : -16

PR verification Self-Check

  • This PR introduces only one functional change.
  • I have updated all required description fields above.
  • My PR adheres to Contributing Guidelines and Documentation.
  • My PR is still work in progress (not ready for review).
  • My PR is ready for review and can be safely merged into a codebase.

Copy link
Copy Markdown
Contributor

@cederom cederom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @HongChao6 very useful utility :-)

Please read https://github.com/apache/nuttx/blob/master/CONTRIBUTING.md and update git commit descriptions :-)

I am wondering if nuttx-apps/testing/input would not be a better fit for this tool? The main purpose is testing / input not really graphics right? Also exiting code in graphics/input? What do you think folks? :-)

@HongChao6
Copy link
Copy Markdown
Author

Thank you @HongChao6 very useful utility :-)

Please read https://github.com/apache/nuttx/blob/master/CONTRIBUTING.md and update git commit descriptions :-)

I am wondering if nuttx-apps/testing/input would not be a better fit for this tool? The main purpose is testing / input not really graphics right? Also exiting code in graphics/input? What do you think folks? :-)

Thanks for the suggestion. The getevent tool shares the same input subsystem infrastructure with monkey and generator under graphics/input/. Moving getevent alone would split the input toolset.

If the community agrees that graphics/input is not the right place, I'd prefer to create a separate PR to move the entire graphics/input/ directory to testing/input/ together, rather than splitting them up in this PR.

What do you think?

@HongChao6 HongChao6 requested a review from cederom March 25, 2026 06:34
acassis

This comment was marked as outdated.

Copy link
Copy Markdown
Contributor

@acassis acassis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@HongChao6 please create a Documentation about this Graphics Input Getevent, I think we also need some basic Documentation about Graphics Input in general

@cederom
Copy link
Copy Markdown
Contributor

cederom commented Mar 25, 2026

@acassis is this input tightly coupled with graphics? if not and can be used as general input then maybe we should create a separate and dedicated nuttx-apps/input ? :-)

@acassis
Copy link
Copy Markdown
Contributor

acassis commented Mar 25, 2026

@acassis is this input tightly coupled with graphics? if not and can be used as general input then maybe we should create a separate and dedicated nuttx-apps/input ? :-)

AFAIK Graphics Input is mostly used to create Monkey testing events, but a generic Input device tester

@cederom
Copy link
Copy Markdown
Contributor

cederom commented Mar 25, 2026

Okay not to delay here we can put where existing input resides :-) Just an idea to uncover this functionality into its own space :-)

Copy link
Copy Markdown
Contributor

@cederom cederom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO :-)

  • PR description.
  • Documentation.
  • Kconfig description.

@cederom
Copy link
Copy Markdown
Contributor

cederom commented Mar 25, 2026

I have created a dedicated issue for discussion of input location #3436 :-)

simbit18
simbit18 previously approved these changes Mar 26, 2026
@simbit18
Copy link
Copy Markdown
Contributor

Hi @HongChao6, this error is not related to this PR

You will need to wait for this PR #3440 to be merged, after which you will need to rebase

====================================================================================
Configuration/Tool: sim/citest
2026-03-27 02:48:55
------------------------------------------------------------------------------------
  Cleaning...
  Configuring...
  Building NuttX...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0

100 1646k  100 1646k    0     0  3078k      0 --:--:-- --:--:-- --:--:-- 5899k

100  143k    0  143k    0     0   286k      0 --:--:-- --:--:-- --:--:--  286k
  Running NuttX...
++ pwd
+ olddir=/github/workspace/sources/nuttx
+ nuttdir=/github/workspace/sources/nuttx/boards/sim/sim/sim/configs/citest/../../../../../../
+ cd /github/workspace/sources/nuttx/boards/sim/sim/sim/configs/citest/../../../../../../
+ confpath=/github/workspace/sources/nuttx/boards/sim/sim/sim/configs/citest/config.yaml
+ jsonconf=/github/workspace/sources/nuttx/boards/sim/sim/sim/configs/citest/session.json
+ testpath=/github/workspace/nuttx-ntfc/external/nuttx-testing
+ ntfc test --testpath=/github/workspace/nuttx-ntfc/external/nuttx-testing --confpath=/github/workspace/sources/nuttx/boards/sim/sim/sim/configs/citest/config.yaml --jsonconf=/github/workspace/sources/nuttx/boards/sim/sim/sim/configs/citest/session.json
/github/workspace/sources/nuttx/../nuttx/boards/sim/sim/sim/configs/citest/run.sh: line 35: ntfc: command not found
+ ret=127
+ echo 127
+ artifacts=/github/workspace/buildartifacts/sim/citest//ntfc
+ mkdir -p /github/workspace/buildartifacts/sim/citest//ntfc
127
+ rm -f pytest.debug.log
+ mv result /github/workspace/buildartifacts/sim/citest//ntfc
mv: cannot stat 'result': No such file or directory
+ cd /github/workspace/sources/nuttx
+ exit 127
  [1/1] Normalize sim/citest
====================================================================================

@HongChao6
Copy link
Copy Markdown
Author

Hi @HongChao6, this error is not related to this PR

You will need to wait for this PR #3440 to be merged, after which you will need to rebase

Thanks for the heads up! I'll rebase once #3440 is merged.

@simbit18
Copy link
Copy Markdown
Contributor

@HongChao6 please rebase

@HongChao6 HongChao6 force-pushed the getevent branch 2 times, most recently from be70cf1 to d7ce4f6 Compare March 30, 2026 06:10
@HongChao6
Copy link
Copy Markdown
Author

@simbit18 The xtensa-03 failure is unrelated to this PR. It's caused by the Xtensa common-source integration update (nuttx#18614) which requires new Kconfig options for ESP32-S3 defconfigs. See esp_irq.c:125 compile error.

@simbit18
Copy link
Copy Markdown
Contributor

Hi @JianyuWang0623, could you please check?

====================================================================================
Configuration/Tool: lckfb-szpi-esp32s3/uvc
2026-03-30 08:01:51
------------------------------------------------------------------------------------
  Cleaning...
  Configuring...
  Building NuttX...
Error: ./common/espressif/esp_irq.c:125:4: error: #error "CONFIG_ARCH_MINIMAL_VECTORTABLE_DYNAMIC must be enabled for           Xtensa-based Espressif SoCs. Additionally, enable           CONFIG_ARCH_IRQ_TO_NDX and set CONFIG_ARCH_NUSER_INTERRUPTS to 2.          Run 'make menuconfig' to select and set these options."
  125 | #  error "CONFIG_ARCH_MINIMAL_VECTORTABLE_DYNAMIC must be enabled for \
      |    ^~~~~
ERROR: xtensa-esp32s3-elf-gcc failed: 1

Linux (xtensa-03)

@JianyuWang0623
Copy link
Copy Markdown
Contributor

Hi @JianyuWang0623, could you please check?

====================================================================================
Configuration/Tool: lckfb-szpi-esp32s3/uvc
2026-03-30 08:01:51
------------------------------------------------------------------------------------
  Cleaning...
  Configuring...
  Building NuttX...
Error: ./common/espressif/esp_irq.c:125:4: error: #error "CONFIG_ARCH_MINIMAL_VECTORTABLE_DYNAMIC must be enabled for           Xtensa-based Espressif SoCs. Additionally, enable           CONFIG_ARCH_IRQ_TO_NDX and set CONFIG_ARCH_NUSER_INTERRUPTS to 2.          Run 'make menuconfig' to select and set these options."
  125 | #  error "CONFIG_ARCH_MINIMAL_VECTORTABLE_DYNAMIC must be enabled for \
      |    ^~~~~
ERROR: xtensa-esp32s3-elf-gcc failed: 1

Linux (xtensa-03)

@simbit18 The fix commit is currently undergoing CI checks: apache/nuttx#18650

@simbit18
Copy link
Copy Markdown
Contributor

@JianyuWang0623 Thank you very much

@linguini1
Copy link
Copy Markdown
Contributor

Hi @HongChao6 , can you please include the impact and test sections in your PR from the contribution guide?

@simbit18
Copy link
Copy Markdown
Contributor

Hi @HongChao6 please rebase

PR apache/nuttx#18650 has been merged

@linguini1
Copy link
Copy Markdown
Contributor

Looks good besides a few small comments!

@HongChao6
Copy link
Copy Markdown
Author

HongChao6 commented Apr 1, 2026

Thanks for the review @linguini1! I agree with the GETEVENT_ERR macro and printf for show_usage — those changes make sense and I'll apply them.

Regarding GETEVENT_INFO and LOG_INFO: since getevent is an interactive command-line tool where the event data output is directly requested by the user, I'm wondering if printf (stdout) would be a better fit here as well, rather than syslog at any level. My reasoning:

Event data is user-facing output, not system log messages
Using printf avoids dependency on CONFIG_SYSLOG_LEVEL — with LOG_INFO, output could be silently filtered on systems with a higher default syslog threshold
This is consistent with how Android's getevent works (stdout)
syslog would still be used for actual errors via GETEVENT_ERR
What do you think? Happy to go with LOG_INFO if you prefer keeping syslog for everything.

@linguini1
Copy link
Copy Markdown
Contributor

Go with printf!

@linguini1
Copy link
Copy Markdown
Contributor

I suppose similarly, wouldn't you want to use fprintf to stderr instead of syslog errors? You can also remove the macros entirely and directly write printf since they're just wrappers.

@HongChao6
Copy link
Copy Markdown
Author

I suppose similarly, wouldn't you want to use fprintf to stderr instead of syslog errors? You can also remove the macros entirely and directly write printf since they're just wrappers.

Good point, I'll switch GETEVENT_ERR to use fprintf(stderr, ...) instead of syslog.

I'd prefer to keep the macros though — they provide a consistent [getevent]: prefix across all output, so if the format ever needs to change, it's a single-line edit. Without them, the prefix string would be duplicated in every call site.

I'll update and push shortly.

@linguini1
Copy link
Copy Markdown
Contributor

Forgot about the prefix, makes sense!

Add getevent utility for monitoring input events including
mouse clicks/movement, multi-touch coordinates/pressure,
and keyboard key presses. Supports automatic device detection
in /dev and command-line device path specification with
non-blocking I/O.

Signed-off-by: liuhongchao <liuhongchao@xiaomi.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants