Keyboard and Mouse controls in new windows

Hi all

I’ve been trying to get accept statements and inputManagers to work in a new window. i Have

class LevelEditor(DirectObject.DirectObject):

    def __init__(self, location):

        self.bool = True

        self.initEditor()
        self.initPlayer()
        self.setCamera()
        self.skyBox()
        self.controlListener()
        taskMgr.add(self.update, "LevelEditUpdate")
        self.accept("mouse1", self.makePlatform)

ive also tried no directObject inheritance, base.accept, and self.win1.accept where win1 is the window i want. Ive also tried checking if the current window has the pointer and keyboard with

if self.win1.hasKeyboard(0):
    self.accept("mouse1", self.makePlatform)
    print(':D')
else:
    print('D:') 

and i get a :smiley: printed but the event doesnt seem to be sent?

Hmm… Have you added any printouts to that method to check whether the control reaches it? Have you tried adding “base.disableMouse()” to your init method, at some point before accepting “mouse1”, in order to disable the default mouse controls?

Disabling default mouse controls could be helpful and ill try that when i get home, but that doesnt explain why i cant seem to get keyboard input working in a second window. Thanks for the reply!

no go with disabling the mouse - its something with the accept statement. clicking doesnt seem to be generating the “mouse1” event its like its called something else.

do the mice names change when new windows are opened? im extremely confused as to why this isnt working

Hmm… I don’t know, I’m afraid. Hopefully someone else will have an answer for you - I’m sorry. :confused:

it could be an issue with the snapshot im using, very unlikely tho. Ill try installing 1.8.0 and see what happens, anyone else have any input on this?

so ive been trying to trace this down by printing out the input device names to make sure the second window has mouse and keyboard devices enabled.

for x in range(self.win1.getNumInputDevices()):
            print(self.win1.getInputDeviceName(x))

printed out

keyboard_mouse
____HID_VID_1532_PID_010D_MI_02.7_707f9b4_0_0000
____HID_VID_056A_PID_00DD_MI_00_Col01.7_35a37641_0_0000
____HID_VID_1532_PID_0015_MI_00.7_3a8b9f2e_0_0000

are there differentr messages generated by keyboard and mice in different windows. Ex: “mouse1” would be “win1mouse1” in another window?

You need to create a MouseWatcher for the new window. This is what base.setupMouse() does. There are several threads in the forum that discuss this, see:

[Events in new window)
[Mouse events in several windows)

David

Your a life saver :smiley: as always thanks for the reply!

so ive been reading through those two links and i ended up with the following code

def initEditor(self):
        #win = base.openWindow()
        self.wp = WindowProperties()
        #base.makeAllPipes()
        pipe = base.pipeList[0]
        self.wp.setSize(pipe.getDisplayWidth() - 60, pipe.getDisplayHeight() - 60)
        self.wp.setOrigin(30, 30)

        self.win1 = base.openWindow(props = self.wp)
        base.setupMouse

        self.myRender = NodePath('myRender')
        base.camList[-1].reparentTo(self.myRender)

        base.camera1 = base.camList[-1]

which results in the window still not accepting the mouse events, so i tried

base.setupMouse(self.win1)

which results in both windows closing but generating no error. Is there something stupid im overlooking?

alrighty i got it after reading more closely from the second link. Ill need to poke around the showBase class to see why it works lol

edit

def makePlatform(self):
        self.sizeEntry = DirectEntry(text="", scale=.05, command=self.setSize, initialText="", numLines=1, focus=1)
        #self.sizeEntry.setPos(-.225, 0, 0.2)
        self.sizeEntry.reparentTo(self.myRender)
        self.sizeEntry.setPos(self.node.getPos())
        self.sizeEntry.setScale(1.5)

i cant seem to input any form of text into the DirectEntry after its made, the main window is still effected by keyboard input as well.

        self.buttonThrowers = []
        for i in range(self.win1.getNumInputDevices()):
            name = self.win1.getInputDeviceName(i)
            mk = base.dataRoot.attachNewNode(MouseAndKeyboard(self.win1, i, name))
            mw = mk.attachNewNode(MouseWatcher(name))
            mb = mw.node().getModifierButtons()
            bt = mw.attachNewNode(ButtonThrower("buttons%s" % (i)))
            if (i != 0):
                bt.node().setPrefix('mousedev'+str(i)+'-')
            mods = ModifierButtons()
            bt.node().setModifierButtons(mods)
            self.buttonThrowers.append(bt)

am i missing something in this code?

DirectGui is a whole other ball of wax. If you want DirectGui objects to work in the second window, you also need to create a PGTop node to be at the root of the 2-d scene graph for the second window, and point this PGTop to your new window’s MouseWatcher.

David

That makes sense, thanks for the reply, ill see what i can do after browsing thru the directGui code :smiley: by setting up directgui in the new window will I have to remove it from the main window so it doesn’t react to keypresses while im typing in the new window?

It’s possible to have DirectGui enabled in multiple windows simultaneously; it just means a different PGTop node for each one.

David

thanks :slight_smile: so i need to create a render2d node than a PGtop node thats attached to that and i pass that to the mousewatcher? sorry im unfortunately new to digging around in panda’s source

so ive ended up with

self.buttonThrowers = []
        for i in range(self.win1.getNumInputDevices()):
            name = self.win1.getInputDeviceName(i)
            mk = base.dataRoot.attachNewNode(MouseAndKeyboard(self.win1, i, name))
            mw = mk.attachNewNode(MouseWatcher(name))
            bt = mw.attachNewNode(ButtonThrower("buttons%s" % (i)))
            if (i != 0):
                bt.node().setPrefix('mousedev'+str(i)+'-')
            mods = ModifierButtons()
            bt.node().setModifierButtons(mods)
            self.buttonThrowers.append(bt)

            render2d = NodePath('render2d')
            render2dp = NodePath('render2dp')
            aspect2d = render2d.attachNewNode(PGTop("aspect2d"))
            aspect2dp = render2dp.attachNewNode(PGTop("aspect2dp"))
            aspect2d.node().setMouseWatcher(mw.node())
            aspect2dp.node().setMouseWatcher(mw.node())
            mw.node().addRegion(PGMouseWatcherBackground())

but to no avail. keyboard and mouse events are working but i still cant get directGui objects to accept input.