Properly use keyboard to type inside Labels?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Dumuz

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.

Try text edit node

Izzyaccess | 2021-09-09 00:18

:bust_in_silhouette: Reply From: dethland

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.

Didn’t know this node existed, thanks!

Dumuz | 2021-08-21 05:02

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.

Dumuz | 2021-08-21 05:16

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:
Reddit - Dive into anything

I have no experience with mobile, so I probably can’t help the first question.
Here is a tab that may relate to that:
https://forum.godotengine.org/28901/virtual-keyboard-help-managing-mobile-device-input

dethland | 2021-08-21 06:23

:bust_in_silhouette: Reply From: j5E01

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
            else:
                caps_enabled = false
        match event.scancode:
            KEY_A:
                if event.shift or caps_enabled == true:
                    myLabel.text = "A"
                    return
                else:
                    myLabel.text = "a"
                    return

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.
07

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.

Dumuz | 2021-09-09 23:47