Key problems

Hey you guys,

I have a few problems with keybindings. I’ve got everything set-up like in the Raoming Ralph Demo but Panda refuses to accept the combination: space, up and right. The character jumps with space and walks with the arrow keys. I’ve tried replacing space with enter, but then the combination: enter, right, down, doesn’t work.
I’ve asked a classmate of mine if he was having the same problem and he was, so my question is… is anyone else familiar with the problem and is there a solution?

Thanks in advance,


There’s a solution…
You have to write something like this:

self.accept('a', self.button, [1])
self.accept('a-up', self.button, [0])

def button(self, keydown):
    if keydown:
        taskMgr.add(self.action, 'ActionTask')

def action(self, task):
    Do something here...
    return Task.cont

As a suggestion: reading someone elses code might help!
I had the the problem as you did, when I started with Panda a few weeks ago (wanted to handle multiple key presses at once), and the solution was found in the source code of someone else.
So look through the forum and source code of others, it’ll answer you question you didn’t even have before :wink:

Thanks, but i actually have something very simular. Let me post some code here:

self.accept("space", self.setKey, ["jump",1])
        self.accept("arrow_left", self.setKey, ["left",1])
        self.accept("arrow_right", self.setKey, ["right",1])
        self.accept("arrow_up", self.setKey, ["forward",1])
        self.accept("arrow_down", self.setKey, ["back",1])
        self.accept("a", self.setKey, ["cam-left",1])
        self.accept("s", self.setKey, ["cam-right",1])
        self.accept("enter", self.setKey, ["cam-snap",1])

        self.accept("space-up", self.setKey, ["jump",0])
        self.accept("arrow_left-up", self.setKey, ["left",0])
        self.accept("arrow_right-up", self.setKey, ["right",0])
        self.accept("arrow_up-up", self.setKey, ["forward",0])
        self.accept("arrow_down-up", self.setKey, ["back",0])
        self.accept("a-up", self.setKey, ["cam-left",0])
        self.accept("s-up", self.setKey, ["cam-right",0])
        self.accept("enter-up", self.setKey, ["cam-snap",0])

That’s to accept them, nothing new here.

def setKey(self, key, value):
        self.keyMap[key] = value

That’s to put them in the array exactly like in the Ralph demo.

And the jump and move task are two different tasks. I don’t need to read them out both at once, i just need them to be in the array as a 1 when they are pressed. That’s not happening right now. With space, it’s only right and up at the same time that doesn’t work, the rest does (i.e. right and down).

I seem to have found your solution ^^
(< same school, different project)

The keyboards here are not very… good. Doing a comparative test with some commercial 3d applications on this computer, i discovered that they just don’t accept any more keys the same time. The erratic behavior (some key combi’s can be pressed at the same time) is probably caused by some lowlevel complications (taking more bits).

I think we may safely assume the problem stops at the keyboard in the classical pebkac situation :wink: *

Yep! SilentStorm likely hit the nail right on the head.

For more information about this issue, has a decent article on computer keyboards.

Long story short: for many keyboards, certain key combinations actually use the same circuitry for detection. If you press multiple keys in one of these combinations, the keyboard hardware can’t disambiguate the signal (sort of like pushing down three buttons in an L-shape on a touch-tone phone). The end result is that one or more keys get dropped.

Frequently, you can alleviate this problem by moving some functionality to modifier keys (shift, control, alt). Because they are intended to modify other keypresses, the circuitry underpinning those keys is dedicated and allows them to be depressed in any combination with at least one other non-modifier key. Try moving whatever you’re doing on space to shift or control.

Best of luck!