class_docstr: Class for window rendering in all MuJoCo environments.
class_docstr_tok: ["Class","for","window","rendering","in","all","MuJoCo","environments","."]
code: def _key_callback(self, window, key, scancode, action, mods):
      if action != glfw.RELEASE:
          return
      # Switch cameras
      elif key == glfw.KEY_TAB:
          self.cam.fixedcamid += 1
          self.cam.type = mujoco.mjtCamera.mjCAMERA_FIXED
          if self.cam.fixedcamid >= self.model.ncam:
              self.cam.fixedcamid = -1
              self.cam.type = mujoco.mjtCamera.mjCAMERA_FREE
      # Pause simulation
      elif key == glfw.KEY_SPACE and self._paused is not None:
          self._paused = not self._paused
      # Advances simulation by one step.
      elif key == glfw.KEY_RIGHT and self._paused is not None:
          self._advance_by_one_step = True
          self._paused = True
      # Slows down simulation
      elif key == glfw.KEY_S:
          self._run_speed /= 2.0
      # Speeds up simulation
      elif key == glfw.KEY_F:
          self._run_speed *= 2.0
      # Turn off / turn on rendering every frame.
      elif key == glfw.KEY_D:
          self._render_every_frame = not self._render_every_frame
      # Capture screenshot
      elif key == glfw.KEY_T:
          img = np.zeros(
              (
                  glfw.get_framebuffer_size(self.window)[1],
                  glfw.get_framebuffer_size(self.window)[0],
                  3,
              ),
              dtype=np.uint8,
          )
          mujoco.mjr_readPixels(img, None, self.viewport, self.con)
          imageio.imwrite(
              self._image_path % self._image_idx, np.flipud(img)
          )
          self._image_idx += 1
      # Display contact forces
      elif key == glfw.KEY_C:
          self._contacts = not self._contacts
          self.vopt.flags[
              mujoco.mjtVisFlag.mjVIS_CONTACTPOINT
          ] = self._contacts
          self.vopt.flags[
              mujoco.mjtVisFlag.mjVIS_CONTACTFORCE
          ] = self._contacts
      # Display coordinate frames
      elif key == glfw.KEY_E:
          self.vopt.frame = 1 - self.vopt.frame
      # Hide overlay menu
      elif key == glfw.KEY_H:
          self._hide_menu = not self._hide_menu
      # Make transparent
      elif key == glfw.KEY_R:
          self._transparent = not self._transparent
          if self._transparent:
              self.model.geom_rgba[:, 3] /= 5.0
          else:
              self.model.geom_rgba[:, 3] *= 5.0
      # Geom group visibility
      elif key in (
          glfw.KEY_0,
          glfw.KEY_1,
          glfw.KEY_2,
          glfw.KEY_3,
          glfw.KEY_4,
      ):
          self.vopt.geomgroup[key - glfw.KEY_0] ^= 1
      # Quit
      if key == glfw.KEY_ESCAPE:
          print("Pressed ESC")
          print("Quitting.")
          glfw.destroy_window(self.window)
          glfw.terminate()
  
imports: import collections
  import os
  import time
  from threading import Lock
  import glfw
  import imageio
  import mujoco
  import numpy
label_desc: Use image node_id 2 for calling the Viewer obj's underlying member method code with example usage: obj._key_callback(window, key, scancode, action, mods) without return types