Add KeyEvent and MouseEvent creation and injection support for Python#7417
Add KeyEvent and MouseEvent creation and injection support for Python#7417Chevi-Koren wants to merge 2 commits intoisl-org:mainfrom
Conversation
- Add Python constructors for KeyEvent and MouseEvent - Add Window.post_key_event() and Window.post_mouse_event() methods - Include thread-safe event injection using PostToMainThread - Add example scripts demonstrating the functionality Fixes isl-org#7346
|
Thanks for submitting this pull request! The maintainers of this repository would appreciate if you could update the CHANGELOG.md based on your changes. |
|
@ssheorey |
|
Hi @Chevi-Koren your virtual environment was added to the PR. Can you please remove that? |
|
Hi @Chevi-Koren have you looked at GUI automation tools? Here are some examples: https://en.wikipedia.org/wiki/Comparison_of_GUI_testing_tools https://github.com/jordansissel/xdotool Not sure if there is a good case for including this in Open3D. |
- Add Python constructor for gui.KeyEvent with type, key, is_repeat - Add convenient factory methods for gui.MouseEvent: * move() - create mouse move events * button_down() - create button press events * button_up() - create button release events * wheel() - create mouse wheel events - Add Window.post_key_event() and Window.post_mouse_event() for thread-safe event injection from Python - Add comprehensive docstrings with examples and parameter docs - Add validation examples demonstrating event injection - Update CHANGELOG.md This enables programmatic GUI testing and event simulation for automated testing scenarios. Resolves isl-org#7346
|
@ssheorey Thanks for the suggestion and for pointing to existing GUI automation tools — that’s a fair point. I wanted to clarify expectations before going further: My main motivation here is enabling: reproducible interaction scenarios lightweight automation without OS-level dependencies easier debugging and example-driven testing within Open3D That said, if the maintainers’ preference is to rely on external automation tools instead, I’m happy to stop or redirect the work accordingly. |
Type
Motivation and Context
Currently, KeyEvent and MouseEvent objects in Open3D's Python GUI can only be generated from real user input. This limitation makes it difficult to write automated tests, reproduce interaction scenarios, or simulate GUI behavior programmatically.
This PR enables programmatic creation and injection of GUI input events from Python, allowing users to simulate keyboard and mouse interactions in a controlled and repeatable way.
Description
This PR adds Python support for creating and injecting KeyEvent and MouseEvent objects into an Open3D GUI window, addressing issue #7346.
The implementation follows the existing Open3D GUI architecture and ensures all injected events are processed safely on the GUI thread.
Changes Made
KeyEvent Support:
gui.KeyEvent(type, key, is_repeat)Window.post_key_event(event)to enqueue a KeyEvent for processing by the window.MouseEvent Support:
gui.MouseEvent.move(...)gui.MouseEvent.button_down(...)gui.MouseEvent.button_up(...)gui.MouseEvent.wheel(...)Window.post_mouse_event(event)to enqueue a MouseEvent.Thread Safety:
post_key_eventandpost_mouse_eventuseApplication::PostToMainThreadinternally.Examples:
examples/python/visualization/gui_key_events.pyexamples/python/visualization/gui_mouse_events.pyThe examples demonstrate:
Due to the presence of a GUI window, an event loop, and timing dependencies, this functionality is demonstrated via executable examples rather than traditional unit tests.
Usage Example