Page MenuHome

WM Event Simulation Support

Authored by Campbell Barton (campbellbarton) on Jan 30 2019, 11:19 PM.



This adds the ability for Python to send events into the event queue (using RNA).

This is intended for writing interaction tests, which I've started doing for the undo system.


  • --enable-event-simulate enables events to be added via Window.event_simulate
  • When G_DEBUG_EVENTS_SIMULATE is enabled, user keyboard and mouse events are ignored.

    Useful so tests can be run without stray mouse events interfering.

    This also keeps the feature *testing-only*, not something for developers to use for nasty hacks.
  • can only be disabled, never enabled.

    Useful for checking the result of running a test.
  • This patch includes some test scripts, they're not for review, just examples of how it can be used.

    They need to be updated to validate the output is correct. Currently I'm just using them for bugs that crash Blender.

Open Topics:

  • We could add events at different levels, eg: generate ghost events instead.

    It would have some advantages since lower level events could be generated but it would be a bigger patch to interface Python w/ ghost, don't think it's worth the extra hassle.
  • Using keyboard/mouse events to test things isn't perfect because they break when shortcuts change. We could consider alternatives. OTOH, the tests end up being short making them quicker to update. There is also an advantage in being able to translate user steps into something that can be automated, w/o having to lookup API docs.
  • We may eventually want to access other UI elements too, but would only consider this later on.

Diff Detail

rBS Blender Staging
Build Status
Buildable 2823
Build 2823: arc lint + arc unit

Event Timeline

Campbell Barton (campbellbarton) retitled this revision from Experimental event playback, use for testing events to WM Event Simulation Support.Jan 30 2019, 11:32 PM
Campbell Barton (campbellbarton) edited the summary of this revision. (Show Details)
Campbell Barton (campbellbarton) edited the summary of this revision. (Show Details)

Yield more specific types (be less vague)

Fix accessing freed event in Python

Error when event arguments that don't make sense are passed in.

Update texture painting test for T60954

Rename command line arg '--debug-events-simulate' to '--enable-event-simulate'

Seems generally fine, just some minor comments.


I suggest to initialize wmEvent e = win->eventstate; and then fill in the other fields.

That's what the WM code does as well so it's maybe a bit more future proof in case extra fields get added.


Maybe name this instead of


ty -> event_type would be more clear

Campbell Barton (campbellbarton) marked 2 inline comments as done.Feb 8 2019, 9:04 AM
Campbell Barton (campbellbarton) abandoned this revision.
Campbell Barton (campbellbarton) added inline comments.

It's still called easy_keys, but it's just part of the tests in SVN, dont have strong opinion, it's just helper module, not something more general for the moment.

Could rename