0 votes

So I made a dictionary with the key:value pair of (KEY_(SOME CHARACTER):"some character"). Then I wrote the following code to display a message that I type out on the keyboard.

var message = ""
func _process(delta):
    self.clear()
    self.add_text(message)
func _input(event):
    if event.type == InputEvent.KEY:
        for i in keys: # keys is the dictionary I mentioned
             if event.scancode == i:
                  message += keys[i]

The problem here is that if I hold a key down, the program will still keep recieving input. And the program runs way faster then I type, resulting in messages like this (hheeeellllo wwwoorrld) from just trying to type regularly. Any built in method that can fix this?

Update 1: I tried

if event.type == InputEvent.KEY and !event.is_echo()

but I still got the same result. Using

if event.type == InputEvent.KEY and !event.is_pressed()

works way better, but with the above code I notice a lag between when I type a character, and when it is displayed on the screen. Anyone know why that lag is there?

asked Jul 21, 2017 in Engine by Daniel Schechtman (28 points)
edited Jul 22, 2017 by Daniel Schechtman

1 Answer

0 votes

You are receiving an event echo, do:

event.type == InputEvent.KEY && !event.is_echo() #and not is_echo
answered Jul 21, 2017 by eons (6,916 points)

I am curious, there is not much of a description in the API, what is an echo?

I've just been using event.is_pressed() to know if the key is held or not.

I guess is a hardware/driver "feature" on keyboards.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.