Function not called using arrow keys

Hi,
There seems to be a simple problem and I can’t see what it is I could be missing. I want a function called when the up, left and space keys are pressed, but this doesn’t happen. The weird thing is that the function is called when the up, right and space keys are pressed, some code:

        #input tests:
        self.in_game_key_map={"front":0, "back":0, "left":0, "right":0, "up":0, "down":0, "jump":0, "wheel-in":0, "wheel-out":0}
        #accepts:
        self.accept('arrow_up', self.set_mot_flat_keyz, ["front",1])
        self.accept('arrow_down', self.set_mot_flat_keyz, ["back",1])
        self.accept('arrow_right', self.set_mot_flat_keyz, ["right",1])
        self.accept('arrow_left', self.set_mot_flat_keyz, ["left",1])
       
        self.accept('arrow_up-up', self.set_mot_flat_keyz, ["front",0])
        self.accept('arrow_down-up', self.set_mot_flat_keyz, ["back",0])
        self.accept('arrow_right-up', self.set_mot_flat_keyz, ["right",0])
        self.accept('arrow_left-up', self.set_mot_flat_keyz, ["left",0])
        
        self.accept("space", self.set_mot_flat_keyz, ["jump",1])
        self.accept("space-up", self.set_mot_flat_keyz, ["jump",0])

   def set_mot_flat_keyz(self,key,value):
       print("GOT?: ",key,value)

What could I be missing? It’s strange that if you press up+right+space on your keyboard, the function is called, but if you press up+left+space, instead, the function is not called. Why is it only working for that one combination of 3: up+right+space?

Just press up+right simultaneously, then tap the space button to see a message on the console. Now try pressing up+left simultaneously instead and try tapping the space button, nothing is printed out…

(It works for each individual key presses as well as any combination of 2.)

Thanks in advance.

This may be the problem of a cheap keyboard. Even the left + up + right + space combination works for me.

1 Like

Does the: up+left (pressed together), then tapping the space bar work too?

That’s weird, I tried doing this on my laptop and it still doesn’t work, however, on the laptop, the back+left+space also works, but not on my desktop.

Maybe, it could be a hardware issue that has nothing to do with Panda3d.

It may well be as serega says, above: some keyboards have issues with certain combinations of keys, as I recall–and the space-bar is one of those that may be involved.

It’s entirely plausible that both your laptop and your other keyboard have this issue.

1 Like

That’s something I wasn’t aware of, thanks for bringing it to my attention. I’ll leave the post up since it’s somewhat relevant to Panda3D, just in case anyone runs into the same puzzling problem.

1 Like

Yes, it works.

from direct.showbase.ShowBase import ShowBase

class Game(ShowBase):
  def __init__(self):
    ShowBase.__init__(self)
    
    self.in_game_key_map={"front":0, "back":0, "left":0, "right":0, "up":0, "down":0, "jump":0, "wheel-in":0, "wheel-out":0}
    
    self.accept('arrow_up', self.set_mot_flat_keyz, ["front",1])
    self.accept('arrow_down', self.set_mot_flat_keyz, ["back",1])
    self.accept('arrow_right', self.set_mot_flat_keyz, ["right",1])
    self.accept('arrow_left', self.set_mot_flat_keyz, ["left",1])
       
    self.accept('arrow_up-up', self.set_mot_flat_keyz, ["front",0])
    self.accept('arrow_down-up', self.set_mot_flat_keyz, ["back",0])
    self.accept('arrow_right-up', self.set_mot_flat_keyz, ["right",0])
    self.accept('arrow_left-up', self.set_mot_flat_keyz, ["left",0])
        
    self.accept("space", self.set_mot_flat_keyz, ["jump",1])
    self.accept("space-up", self.set_mot_flat_keyz, ["jump",0])
    
  def set_mot_flat_keyz(self,key,value):
    print("GOT?: ",key,value)

game = Game()
game.run()

out:

GOT?:  left 1
GOT?:  front 1
GOT?:  jump 1
GOT?:  jump 0
GOT?:  left 0
GOT?:  front 0

Alright, thanks for running it.

Just to add a bit more information on this, your keyboard likely has limited Rollover which causes key jamming when too many buttons are hit.

3 Likes