Detecting any keypress

Greetings all!

I’m attempting to implement the ol’ “press any key to continue” interface trick in the project I’m currently working on. If the way to do this has been posted before, I apologize; I went hunting and wasn’t able to find it.

Is there a higher level at which I can talk to Panda regarding keyboard input than waiting for “key” or “key-up” events? I’d like to be able to detect when any key on the keyboard is pressed, but I don’t see how one does that without registering a handler for every possible key.

Thanks,
Mark

You can make the following call:


base.buttonThrowers[0].node().setButtonDownEvent('button')

Then listen for event ‘button’, which will be called with one parameter, the name of the button. I believe this may only work on Panda version 1.2; for earlier versions, there are other, clumsier workarounds.

David

Thank you for the help! That should work nicely.

On a related note: is there a “one true way” to prevent all registered DirectObjects from receiving key events for a time? I’ve got my key handlers distributed throughout the project, and while I’m accepting any key I’d also like to discard the key I receive before one of the handlers gets it (so that if the user chooses to press the fire key, they don’t fire a bullet in addition to unpausing the game).

I’m thinking that if I could interrupt the flow of data from the keyboard handler to the messenger, then I could prevent the key-event messages from getting fired. Is there a location at which the event handlers “know about” the existence of messenger that I could hook into to hide the messenger (or substitute my own, special messenger for the pause state)?

Thank you for the help!

-Mark

You can’t globally intercept messages. But you might consider temporarily replacing (or modifying) the ButtonThrower object, which is responsible for generating messages in response to button events.

For instance, you could do:


base.buttonThrowers[0].node().setPrefix('inop-')

to prefix every event generated by this ButtonThrower with the string “inop-”, e.g. “inop-a”, “inop-a-up”, and so on–so it won’t be received by objects listening for just “a” or “a-up”. You could do this when you pause the game, for instance, and the set the prefix back to its default value, the empty string, when you unpause it.

David

Is this method of setting a generic button handler still valid? I tried doing so and setting the messenger to verbose, but I don’t see a generic ‘button’ event.

Still works for me.

David

Hmm, really strange. I see the specific button events (both in the messenger’s output and in getting the proper callbacks), but not the general event (neither in the output nor getting a callback). Any ideas of where I can start digging around?

Here’s an interesting bit of information, I set base.buttonThrowers[0].node().setSpecificFlag(0), but I am STILL seeing specific button presses. However, there seems to be just the one thrower…

In fact, destroying the entire Mouse/Keyboard node doesn’t seem to do anything either, base.dataRoot.getChildren().asList()[0].removeNode(), specific input events still come in.

Mystery solved, the order of things were (1) load default window (by accident, wrong config file) (2) specify button down events (3) load another window where things actually happen. It appears the events were associated with the first window that I didn’t even realize existed.