Panda3d KeyPressed + 'anotherKey' events

Hai, I am new to Panda3d, and I am creating small python app to move a panda model in normal directions such as forward, backward, left, right using ‘w’, ‘s’, ‘a’, ‘d’ keys respectively. I am able achieve this by using ‘self.accept()’ method available, but the problem is when I am pressing one key, if I press another one then the old key is no more activated, i.e for Eg;- I am pressing ‘w’ to move forward, at the same time if I press ‘a’, the model moves to left, when I release ‘a’ key, still pressing key ‘w’, it does nothing. Well it should be moving forward cause I am still pressing ‘w’ key !!!.
How to do the ‘key pressed’ + ‘anther key’ combination ? I tried it with self.accept(‘w-a’, myMethod) and self.accept(‘w-a-repeat’, myMethod), its not working as desired … !!!
Help needed …

I don’t think there is such a thing as “multiple keys pressed” events. You’d need to track the state of these keys in your own code.

For example, in response to a “w” event, you could set a “upActive = True” boolean; in response to “w-up” you could set “upActive = False”. Do similarly for the other “s”, “a”, and “d” keys.

Then, independently, you could say “taskMgr.add(updateMovement, ‘updateMovement’)” and have the updateMovement() method respond to the …Active booleans to compose the “full” motion. Be sure to have this return “Task.cont” to continue its work every frame.

– Ed

Ok thanks… I’ll give it a try, I also found a chunk of code which does the similar kinda thing like u have said…

Well, I was successful in figuring out a solution for this particular problem. Part of the code:-

self.panda_forward = False

self.accept(‘w’, self.move_panda, [‘w’])
self.accept(‘w-up’, self.move_panda, [‘w-up’])

self.taskMgr.add(self.update_panda, “Update Panda”)

def move_panda(self, key_pressed=None):
if key_pressed == ‘w’:
self.pandaActor.setPlayRate(1.0, “walk”)
self.panda_forward = True
if key_pressed == ‘w-up’:
self.panda_forward = False

def update_panda(self, task):
if self.panda_forward:
self.pandaActor.setY(self.pandaActor, -4)

Thanks for ‘panda3d 1.7 game developer’s cookbook’ and ‘eswartz’ …