Python question with Gamekeys.

Hey all. :wink:

I am making a python script which controlls the actions of a armature with Gamekeys. The problem is that so far I know you can’t press 2 keys at a time if you use that.

When you hold For example W key, and when still holding W key press another key, the action of the W key stops.

Sorry I’m terrible at explaining my problem in English. xD

Anyway, Someone understands me and know a solution? :wink:

Thanks a lot :yes:

edit

cont = GameLogic.getCurrentController()
own = cont.getOwner()

import GameKeys

running = 0
keys = cont.getSensor(“run”)
run = cont.getActuator(“Run”)

wKey = GameKeys.WKEY
aKey = GameKeys.AKEY

if keys.getKeyStatus(wKey) == GameLogic.KX_INPUT_JUST_ACTIVATED:
running = 1
elif keys.getKeyStatus(aKey) == GameLogic.KX_INPUT_JUST_ACTIVATED:
running = 0

if running == 1:
GameLogic.addActiveActuator(run, True)
else:
GameLogic.addActiveActuator(run, False)

I think that is a problem of your script. Because you can press multiple keys at the same time.
When the action stops you deactivated the actuator. If you add some print statements you can see what the script does and when it activates/deactivates the actuator.

I hope it helps

I posted the script. It’s the one you helped to make. xD

just use ifs instead of elif where applicable.

for example:

if keys.getKeyStatus(wKey) == GameLogic.KX_INPUT_JUST_ACTIVATED:
	print "wKey pressed"
if keys.getKeyStatus(aKey) == GameLogic.KX_INPUT_JUST_ACTIVATED:
	print "aKeypressed"

but you cannot trigger both running = 1 and running = 0 in the same frame, so if you just replace the elif with an if in your code it still will give back running = 0 when both keys are pressed.