+1 vote

I'm sure this is a noob question, but I'm still a noob.

How do I properly implement basic typing from a keyboard in a game, that still references things like Capslock being on, or shift being held?

Right now I was using _input(event) and using the method .as_text() and just adding it to the label, but this makes the text coming in as capitalized. I'm sure there's a better way of doing this and I'm just ignorant.

Godot version 3.3
in Engine by (363 points)

Try text edit node

2 Answers

0 votes
Best answer

Maybe try the TextEdit node rather than the label node. The capslock and shift being held are build in it. You can use the focus_entered() signal to determine when to able the node. I hope it will help you.

by (341 points)
selected by

Didn't know this node existed, thanks!

Sorry Follow-up:

TextEdit seems not be compatible with mobile?
Also, I can't seem to figure out how to change the background color, I've clicked through all the custom colors and they don't seem to affect it.

I find the solution for the background color problem. You can active the "Syntax Highlighting" option. Then, change the background color under the Custom Colors branch.

Here is the original tab:

I have no experience with mobile, so I probably can't help the first question.
Here is a tab that may relate to that:

0 votes

I have just went through this swamphole of a problem the last few days, as TextEdit, and LineEdit nodes handled all keyinput with modifiers, but their RECT sizes were limiting and not as freely editable as Label's.
Here's what I've used so far

var caps_enabled

func _input(event):
    if event is InputEventKey and event.pressed:
        if event.scancode == KEY_CAPSLOCK: 
            if caps_enabled == false:
                caps_enabled = true
                caps_enabled = false
        match event.scancode:
                if event.shift or caps_enabled == true:
                    myLabel.text = "A"
                    myLabel.text = "a"

So godot doesn't handle capsLock enabled // disabled yet (check out this github proposal and thumbs it up so it can gain some developer attention), therefore you need to create a variable that can handle the capslock input scancode - which also means that if it's already enabled when the game starts, it will be backwards the entire time.

I couldn't get the code for SHIFT + CAPS_ENABLED to set text to "a" , so i'm just skipping that headache.

Also note, this code is just for the letter A, and will need to be repeated for the entire alphabet, numbers, and then I'm thinking of adding modifiers for ALT codes as well -_-

Anyways, hope this helps.

by (27 points)
edited by

Appreciate the extensive answer. I had to change to with using Label as the Android doesn't seem to support TextEdit. Since the virtual keyboard comes up while the game is open, I can register the capsLock button being pressed get most of what I need from players being able to add some custom text.

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 Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.