MCPcopy Create free account
hub / github.com/google-deepmind/dm_control / GlfwKeyboard

Class GlfwKeyboard

dm_control/viewer/gui/glfw_gui.py:60–89  ·  view source on GitHub ↗

Glfw keyboard device handler. Handles the keyboard input in a thread-safe way, and forwards the events to the registered callbacks. Attributes: on_key: Observable subject triggered when a key event is triggered. Expects a callback with signature: (key, scancode, activity, modifiers

Source from the content-addressed store, hash-verified

58
59
60class GlfwKeyboard(base.InputEventsProcessor):
61 """Glfw keyboard device handler.
62
63 Handles the keyboard input in a thread-safe way, and forwards the events
64 to the registered callbacks.
65
66 Attributes:
67 on_key: Observable subject triggered when a key event is triggered.
68 Expects a callback with signature: (key, scancode, activity, modifiers)
69 """
70
71 def __init__(self, context):
72 super().__init__()
73 with context.make_current() as ctx:
74 ctx.call(glfw.set_key_callback, context.window, self._handle_key_event)
75 self.on_key = util.QuietSet()
76
77 def _handle_key_event(self, window, key, scancode, activity, mods):
78 """Broadcasts the notification to registered listeners.
79
80 Args:
81 window: The window that received the event.
82 key: ID representing the key, a glfw.KEY_ constant.
83 scancode: The system-specific scancode of the key.
84 activity: glfw.PRESS, glfw.RELEASE or glfw.REPEAT.
85 mods: Bit field describing which modifier keys were held down, such as Alt
86 or Shift.
87 """
88 del window, scancode
89 self.add_event(self.on_key, key, activity, mods)
90
91
92class GlfwMouse(base.InputEventsProcessor):

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…