input problem

first of all, hello everyone!

this is my first message and I’d like to thanks carnegie mellon and the panda3d team for the beautiful works they had done.

I’m making my own and free version of g.t.a. 2 and (I new of python too) i got a problem.
i would press the “W” key and make my man move up.

I’ve thinked that when is pressed the key I change the X attribute of the man object… and it works. the only matter is that when I press it the man movea but only for a frame.

how can i do?

thanks

Well, how are you doing it now?

Are you accepting the key event, and in the associated method setting the appropriate coordinate? If so, then yes, I would imagine that you would only get one movement per key depress, since, if I’m not much mistaken, the event fires when the key is depressed, but does not continue to fire as it is held.

Instead, consider using the key-press method to set a variable to True (and the key-release event to reset it to False). In an update method, you then check the state of the variable, and act accordingly. For example, your code may look something like this:

def __init__(self):
     #Allow for two keys - up and down - 
     # and initialise them to False
     self.keys = {"up":False, "down":False} 

     #Accept events for the w- and s- keys being pressed,
     # as well as their being released.  The method
     # "setKey" is defined below.  Note that the last
     # parameter is a list of arguments to pass
     # to the method mentioned directly before it
     self.accept("w", self.setKey, ["up", True])
     self.accept("w-up", self.setKey, ["up", False])
     self.accept("s", self.setKey, ["down", True])
     self.accept("s-up", self.setKey, ["down", False])

def setKey(keyname, value):
     self.keys[keyname] = value

#This is an update task, which should be
# set to repeat each frame (or something
# similar and appropriate to your project)
def update(self, task):
     
     #Somewhere appropriate within the method:
     if keys["up"]
          #Move your object up
     if keys["down"]
          #Move your object down