Carb mouse event callback is not being trigered

I’m try to bind the mouse event callback like this :
self._window = ui.Window(“testing UI”, width=200, height=700, dockPreference=ui.DockPreference.RIGHT)
self._window.deferred_dock_in(“Stage”, ui.DockPolicy.DO_NOTHING)

self._appwindow = omni.appwindow.get_default_app_window()
self._mouse = self._appwindow.get_mouse()
self._input = carb.input.acquire_input_interface()
self._keyboard = self._appwindow.get_keyboard()

    self._sub_mouse = self._input.subscribe_to_mouse_events(self._mouse,sub_mouse_event)
    self._sub_keyboard = self._input.subscribe_to_keyboard_events(self._keyboard, sub_keyboard_event)

both sub_callbacks print to screen, the keyboard callback works fine, however no matter what I do with the mouse it’s doest trigger at all. Any ideas what’s wrong?

Hi @icaroleles1! You have the right idea, but the devs recommended two tweaks.

  1. Use subscribe_to_input_events. It’s a single function that works for all input types.
  2. Set your callback to execute early in the call order.

The result would look like this:

self._appwindow = omni.appwindow.get_default_app_window()
self._mouse = self._appwindow.get_mouse()
self._input = carb.input.acquire_input_interface()
self._keyboard = self._appwindow.get_keyboard()
self._sub_mouse = self._input.subscribe_to_input_events(mouse_event_cb, device=self._mouse, order=0)
self._sub_keyboard = self._input.subscribe_to_input_events(key_event_cb, device=self._keyboard, order=0)

...
# later on, make sure to unsubscribe
def destroy(self) -> None:
        self._input.unsubscribe_to_input_events(self._sub_mouse)
        self._input.unsubscribe_to_input_events(self._sub_keyboard)
        return super().destroy()
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.