Action while holding the key

Hello. How do I make it in a script so that the action works when the key is held? For example, press the key for 3 seconds.

       if SpaceKEY:
          Cube_Property['Player_Space_Timer'] =0 

Hi,

You can try playing the action right when the key is pressed, and then stopping the action right when it is released.

e.g)

from bge import logic

controller = logic.getCurrentController()
owner = controller.owner

keyboard = logic.keyboard

# Store the event of the space bar being pressed/etc.
spaceKey = keyboard.events[bge.events.SPACEKEY]

if spaceKey == logic.KX_INPUT_JUST_ACTIVATED:
    owner.playAction("MyAction", 0, 20)
elif spaceKey == logic.KX_INPUT_JUST_RELEASED:
    # Stop the action only if it is playing.
    if owner.isPlayingAction():
         owner.stopAction()

You will need further/other methods if you want to continue playing the action from that frame the action was left from. One possible solution is storing the action frame before key release, and then playing from that frame with error handling.

Hope that helps.