how to add Tap in keyboard[]

import bge

cont = bge.logic.getCurrentController()
own = cont.owner

Motion = cont.actuators["Motion"]

keyboard =

W = keyboard[]

if W > 0:

in this script how to make the W key active only one time even if we keep holding it, like using Tap in logic bricks?
thank you

if W==1:

I think in upbge

I will check

you can ditch the motion actuators with the functions .applyMovement((x, y, z), Local) and .applyRotation((x, y, z), Local)

import bge

cont = bge.logic.getCurrentController()
own = cont.owner

#Motion = cont.actuators["Motion"]

keyboard =
inactive = bge.logic.KX_INPUT_NONE  # aka 0
tap = bge.logic.KX_INPUT_JUST_ACTIVATED  # aka 1
active = bge.logic.KX_INPUT_ACTIVE  # aka 2
released = bge.logic.KX_INPUT_JUST_RELEASED  # aka 3

W = keyboard[]

if W == tap:
#    cont.activate(Motion)
    own.applyMovement((0, 0.1, 0), True)  # True for Local, False for World
    own.applyRotation((0, 0, 0.1), True)  # Rotation
#    cont.deactivate(Motion)

im using the motion actuators just to test the script, thank you for your code

You are rebuilding the keyboard sensor in Python?

What is wrong using the sensor as it is?

To answer your question - the key event has four status:

  • bge.logic.KX_INPUT_NONE
  • bge.logic.KX_INPUT_ACTIVE

Try this in your file (always sensor true level triggering enabled):

import bge

keyboard = bge.logic.keyboard

w_key_status =[]

if w_key_status == bge.logic.KX_INPUT_NONE:
    print("not pressed")
elif w_key_status == bge.logic.KX_INPUT_JUST_ACTIVATED:
    print("just pressed")
elif w_key_status == bge.logic.KX_INPUT_ACTIVE:
elif w_key_status == bge.logic.KX_INPUT_JUST_RELEASED:
    print("just released")
    print("You should never see this message. There are no other status")

When you read the console output carefully you can guess what you need to check. If not let us know.

  • I somehow passed by here … and did see what I need, too. Thank you.