Add keyboard event callback for Python passive viewer.
Fixes #766 Fixes #846 PiperOrigin-RevId: 549449372 Change-Id: I37d17f1162c66d0e8482d402aae22d9a16b59deb
This commit is contained in:
committed by
Copybara-Service
parent
f7847ba73e
commit
06b70832ce
@@ -160,6 +160,29 @@ illustrative example that does **not** necessarily keep the physics ticking at t
|
||||
if time_until_next_step > 0:
|
||||
time.sleep(time_until_next_step)
|
||||
|
||||
Optionally, ``viewer.launch_passive`` also accepts a callable as a keyword argument ``key_callback``, which gets called
|
||||
each time a keyboard event occurs in the viewer window. This allows user scripts to react to various key presses, e.g.
|
||||
pause or resume the run loop when the spacebar is pressed.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
paused = False
|
||||
|
||||
def key_callback(keycode):
|
||||
if chr(keycode) == ' ':
|
||||
global paused
|
||||
paused = not paused
|
||||
|
||||
...
|
||||
|
||||
with mujoco.viewer.launch_passive(m, d, key_callback=key_callback) as viewer:
|
||||
while viewer.is_running():
|
||||
...
|
||||
if not paused:
|
||||
mujoco.mj_step(m, d)
|
||||
viewer.sync()
|
||||
...
|
||||
|
||||
|
||||
.. _PyUsage:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user