#Need advice on making a custom on-screen keyboard.

1 messages · Page 1 of 1 (latest)

subtle summit
#

Hello! I need some advice on how to make a keyboard that will display text through key presses and button presses.

I'm using a TextEdit to display the text and 12 buttons underneath to add it. I don't know how to connect the two so each button applies text.

I'm brand new to Godot and programming (4 Days) and I took the time to learn GDScript. I don't know enough about Godot to complete this task. Let alone combining text when typed in a certain order.

If anyone has a method or better set of nodes to do this I'd appreciate the recommendations. Thank you.

ruby whale
#

Hi, I recommend starting with a Scene Tree layout like this.

#

You can make a Button scene, add the buttons to the HBoxContainers like so

#

Button scene:

subtle summit
#

I've been able to do that much. I also used control nodes to help organize the buttons.

ruby whale
#
  • Add a new script to the Button node inside of its scene
  • Connect the button's pressed signal to the Button node
#

This makes a new function in your button script.
You then need a way to reference the TextEdit node.
My preferred way for this is using get_tree().current_scene to get the Main node. Then go down from there with get_node() to get the TextEdit node.

extends Button

func _on_pressed():
    get_tree().current_scene.get_node("TextEdit").text += self.text
#

(get_node() with one name inside of the parenthesis, is a quick way to get a child node)

#

(self.text can also just be written as text)

subtle summit
#

And with this it'll display text on the TextEdit?

ruby whale
#

It should, does on my end in my quick little test

subtle summit
#

I'll try it now then. Thank you!

ruby whale
#

Adds whatever the button's text variable is, into the TextEdit's own text variable

#

Good luck, brb for a bit feel free to ping again

subtle summit
#

I love Noita btw
Noita got me wanting to learn how to code in the first place. I've played that game an ungodly amount of times.

ruby whale
#

Only about a hundred hours here, love it though

subtle summit
#

I'm around 400 hours.

ruby whale
#

Simulating all those pixels would be pretty hard in Godot I'd imagine lol

#

He had to make his own engine didn't he

subtle summit
#

I'm not gonna attempt it. 😅
But I want to make games in the future.

#

I'll ping you if I run into any trouble. I'll have questions in the future for sure. The keyboard I want to make is very unique.

ruby whale
#

Np and I can explain more in depth if you need, back in like 10 mins

#

Like if you don't know how . accesses things you might have trouble

subtle summit
#

I vaguely know about it. I learned a bit of Java before learning GDScript, so I can understand some basic or little things. Just not fully aware or in-depth.

#

I gotta brb for a bit too though.

subtle summit
distant vine
#

an easy way would be:

  • add all buttons to a group
  • let the root of the scene connect the buttons:
var text_edit = %TextEdit # (activate unique name on the node.. or use the path to set the reference)


# then in ready do this:
for button in get_tree().get_nodes_in_group("keyboard"):
  button.pressed.connect(text_edit._on_keyboard_button_pressed.bind(button.text))

TextEdit's _on_keyboard_button_pressed function will receive the button text and can handle it accordingly. If you need to send some other value than the button text you can use meta data on the button nodes with get_meta()

subtle summit
#

I'll try that in a sec.

#

I am still 4 days into this so I might get something wrong.

subtle summit
distant vine
#

sorry I'll go to bed now (eu time)

subtle summit
#

Ahh, I'm cali time.

#

It's all good.

distant vine
#

you can put the code in your scene root (the control node named Node2D). TextEdit should also work, if you want

#

and you know the _ready function, so the where is clear

#

´func _on_keyboard_button_pressed(button_text: String) -> void:´

#

would be the function on text edit

#

for testing you can just add a print statement that prints button_text… if the pressed button's text prints it works

#

gl

subtle summit
#

Alright. I'll try that. Goodnight!

#

And thank you!

subtle summit
#

OMG

#

extends Button

func _on_pressed():
get_tree().current_scene.get_node("Camera2D/TextEdit").text += self.text
print("Jey")

This worked for me! That's one step out the way.