|Topic was automatically imported from the old Question2Answer platform.
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
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!
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 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
if event is InputEventKey and event.pressed:
if event.scancode == KEY_CAPSLOCK:
if caps_enabled == false:
caps_enabled = true
caps_enabled = false
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.
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.