This is the testing Godot forums! All forum posts unique to this forum will be deleted! Please use the main forums here for any posts you want to keep. All forum rules still apply.

How do we disabe an input key when another one is pressed?

mdswampmdswamp Posts: 53Member

Hi people...
when i press a key (for ex: "w"), an animation plays from animated sprite, another key (for ex: "s") does the same for another animation. if i press these two keys quickly, one of them usually does not work and i think pressing one key before releasing another one is the cause of this problem, what i wanna do now is when i press one of them, another one become disable. how should i do this, thank you :)
(im using godot 2.1.5)

Best Answer

  • ZenzorZenzor Posts: 6
    Accepted Answer

    Try a boolean to check if one key is pressed and in a condition

    `var is_keyPressed = false

    func _process(delta):
    if (Input.is_key_pressed("KEY_W") and not is_keyPressed):
    is_keyPressed = true
    play animation`

Answers

  • ZenzorZenzor Posts: 6Member
    Accepted Answer

    Try a boolean to check if one key is pressed and in a condition

    `var is_keyPressed = false

    func _process(delta):
    if (Input.is_key_pressed("KEY_W") and not is_keyPressed):
    is_keyPressed = true
    play animation`

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.