Multiple windows reading mouse events (Solved)

Hello all!

I’m trying to create two windows, each of which read mouse data and send mouse events.

The first window does this by default, but the second window

win2 = base.openWindow()

does not. Can anyone point me in the right direction?

Thank you dearly :slight_smile:


I have tried

base.setupMouse(win2,fMultiWin = True)

this seems to set up the mouse for the window, 2 but disables the mouse for window 1.
I have also attempted to create a MouseWatcher with a ButtonThrower, unfortunately I cannot find too much documentation on either of these classes

Try the following:

from panda3d.core import *
from direct.showbase.ShowBase import ShowBase

class MyApp(ShowBase):

    def __init__(self):


        # Setup environment

        self.scene = self.loader.load_model("environment")
        self.scene.set_pos(-8., 42., 0.)

        # Open new window and set up input control

        win2 = self.open_window()
        mouse_watcher_node = MouseWatcher("win2")
        region = win2.get_display_region(0)
        input_ctrl_node = MouseAndKeyboard(win2, 0, "keyboard_mouse")
        input_ctrl = self.dataRoot.attach_new_node(input_ctrl_node)
        mw = input_ctrl.attach_new_node(mouse_watcher_node)
        btn_thrower_node = ButtonThrower("btn_thrower_win2")
        self.accept("mouse1", lambda: self.__on_left_down(1))
        self.accept("win2_mouse1", lambda: self.__on_left_down(2))

    def __on_left_down(self, window_id):

        print("Left mouse button pressed in window {}!".format(window_id))

app = MyApp()

Oh wow thank you!

I guess you needed to create a new MouseAndKeyboard Node as well… I suppose that makes sense.