I think that I’ve made quite a bit of progress on my key-mapping retro-fit, but I’ve encountered an odd bug: The first time that I click on one of my control-mapping buttons, I get an unintended mouse-event. It happens only that first time in a given run, however–subsequent button-presses don’t produce this behaviour.
Unfortunately, this results in the key-mapper taking that unintended event to be the user’s selected mapping. :/
A little investigation indicates that it seems to be related to the code that generates ButtonThrowers and InputDeviceNodes for additional devices–commenting out that code seems to remove the undesired mouse-event.
I’ve put together a small test-program that demonstrates this behaviour (on my machine, at least).
When first run, this test-program isn’t listening for key-presses. However, pressing the DirectButton that it displays causes it to start doing so; from then on, it should print out notifications of buttons being pressed or released.
On my machine, when I release the mouse-button after pressing the button, I get two mouse-release events: one reporting mouse1, and one reporting mouse3.
If, however, I comment out the section of code that adds ButtonThrowers and InputDeviceNodes for additional devices–but leave in the use of the default keyboard-and-mouse ButtonThrower–I don’t get these unintended events.
Here is the program:
from panda3d.core import ButtonThrower, InputDeviceNode
from direct.gui.DirectGui import DirectButton
from direct.showbase import ShowBase as showBase
class Game(showBase.ShowBase):
def __init__(self):
showBase.ShowBase.__init__(self)
self.accept("escape", self.userExit)
btn = DirectButton(text = "Start accepting presses",
scale = 0.1,
command = self.startAcceptingPresses)
self.buttonThrower = base.buttonThrowers[0].node()
self.accept("keyInterception", self.keyInterception)
self.accept("keyRelease", self.keyRelease)
def startAcceptingPresses(self):
self.buttonThrower.setButtonDownEvent("keyInterception")
self.buttonThrower.setButtonUpEvent("keyRelease")
# Comment out the following to remove the bug
devices = base.devices.getDevices()
for device in devices:
deviceTypeString = str(device.device_class)
thrower = ButtonThrower(deviceTypeString)
thrower.setButtonDownEvent("keyInterception_"+deviceTypeString)
self.accept("keyInterception_"+deviceTypeString, self.keyInterception)
thrower.setButtonUpEvent("keyRelease")
dataNP = base.dataRoot.attachNewNode(InputDeviceNode(device, device.name))
dataNP.node().addChild(thrower)
def keyInterception(self, key):
print (key, "was pressed")
def keyRelease(self, key):
print (key, "was released")
app = Game()
app.run()
Am I doing something incorrectly? Is this a bug in Panda?