The common way to achieve this is to make your car accelerate each frame where the key is down.
You should have a look at the Verlet integration :
# dt : the time delta between the last frame and now
# carPos : the Vec3 position of the car
# acc : the Vec3 acceleration
acc = Vec3(0,0,0)
if keyIsDown :
acc += Vec3(0,5,0) # the car accelerates along the Y axis
acc += Vec3(0,0,-5) # gravity ?
damp = math.exp(-dt / .995) # damping effect
tempPos = Vec3(carPos)
carPos += (carPos - carLastPos) * damp + acc * dt * dt
carLastPos = tempPos
The benefit to use dt is that this code is framerate independent.
Edit :
If you want to keep an array with all the pressed keys, you can try :
# AZERTY :-)
self.keyMap = {
'z' : 'forward',
'q' : 'left',
's' : 'backward',
'd' : 'right',
'r' : 'up',
'v' : 'down'
}
self.keyDown = {}
for key in self.keyMap :
self.keyDown[self.keyMap[key]] = 0
self.accept(key, self.setKey, [self.keyMap[key],1])
self.accept(key + '-up', self.setKey, [self.keyMap[key],0])
####
def setKey(self, key, value):
self.keyDown[key] = value
####
# You can then test is a specific key is down :
if self.keyDown['forward'] :
pass
Then, you can change your keyMap as you want without altering the code