Equivalent of mouseWatcherNode.is_button_down but for a gamepad?

Hello.

I would like to check for gamepad buttons being down in a similar way to using the mouseWatcherNode.

So for example if using KeyboardButton:

self.is_down = self.mouseWatcherNode.is_button_down

and then later in the initializer:

self.up = KeyboardButton.up()
self.d = KeyboardButton.ascii_key('d')
# etc. etc....

and then checking to see if they are pressed in an update() method:

if self.is_down(self.up):
    pass  # do something
if self.is_down(self.d):
    pass  # do something

# etc. etc.

I would like to use this same technique but for gamepad buttons. I noticed there are some methods available under the GamepadButton class:

GamepadButton.dpad_down()
GamepadButton.dpad_left()
# etc. etc.

Is there a way to watch for these gamepad buttons with something like the mouseWatcher???

I already have the controller recognized and buttons working by using the other way:

self.accept('gamepad-dpad_left', self.test, extraArgs=['gamepad-dpad_left'])
self.accept('gamepad-dpad_left-up', self.test, extraArgs=['gamepad-dpad_left-up'])
# etc. etc...

But would rather not do it that way if possible.

Thanks!!!

Method .ascii_key() this is used to enter characters. These are different concepts, interception of buttons and entering characters of letters from the keyboard. This will not work on keyboards if you switch the language layout.

ADD:
Hmm, I checked it works when switching layouts, which is weird. In any case, gamepads do not have ASCII mode.

Perhaps your problem with this approach is that you don’t use a dictionary with button status flags. You can take a look at the roaming-ralph example to familiarize yourself with this approach.

Hmmm okay. I was hoping to read the button down every frame, similar to the polling interface: Keyboard Support — Panda3D Manual

Any idea what these are for and how to read them?

GamepadButton.back()
GamepadButton.dpad_up()
GamepadButton.dpad_down()
GamepadButton.dpad_right()
GamepadButton.dpad_left()
GamepadButton.face_a()
GamepadButton.face_b()
GamepadButton.face_x()
GamepadButton.face_y()
GamepadButton.face_z()
GamepadButton.lstick()

There are a lot more but didn’t want to type them all out. They seem to correspond to gamepad input events, similar to the ones for KeyboardButton().

EDIT: giving a try with this suggestion: check if button is held down? - #5 by enn0x Have no idea if it will work :slight_smile:

Got it! Using this in my initializer (xbox down arrow for example):

inputState.watchWithModifiers('paddown', 'gamepad-dpad_down')

and this in an update() method:

some_var = inputState.is_set('paddown')

successfully returns a bool every frame… only tried with the down arrow so far but it should work with the rest of the Xbox controller’s buttons.

I still wonder about the above GamepadButton lines though

For gamepad and other types of input devices, you can also use the InputDevice class. The steering wheel, flight stick and device_tester samples that ship with panda3d do show how these can be set up and used.

If you want to get the pressed state of a button, you can do myGamepad.findButton(myButtonHandler).pressed

2 Likes

that seems like what I was looking for… will give it a shot in a few minutes