Hmm, that may be the easiest way to get a string from the _input
function in Godot, at least without using a UI element. You may be able to simplify the code a bit though (untested):
extends Label
var nombre = ""
func _input(event):
if event is InputEventKey and event.pressed:
# handle special key codes
if event.scancode == KEY_BACKSPACE:
nombre = nombre.left(nombre.length()-1)
elif event.scancode == KEY_ENTER:
print (nombre)
else:
# all other keycodes, just add them to the string!
nombre += OS.get_scancode_string(event.scancode)
# update the label's text
set_text(nombre)
Edit: Though as a I mentioned, if you just need to get text input, using a node like the LineEdit node would be great for this, as it basically does what the script is doing, but handles it all internally. It also has code so only the LineEdit that is selected will have text appended to it, unlike the script which will grab all input events. That said, if there is a reason that you cannot use a UI node, then something like the script above is probably the best way to handle it.