Keyboard & mouse overlay : which wrapper node is better?

Godot Version

4.3

Question

Hello ! As I am very new to Godot (and game dev actually :smiley: ), i have a basic/dumb question !

I would like to create a keyboard & mouse overlay to help me test my games.
My objective is to make it independent of the screen size and positionned/rescaled in the scene instanciating it…

My biggest issue is : I dont know which node(s) is/are better to wrap all keys !!

I already coded this node, representing a key (mouse or keyboard) :

class_name InputKeyOverlay
extends TextureButton

var action_name : String = ""
var event : InputEvent = null
const DEFAULT_EVENT_PHYSICAL_KEYCODE : int = KEY_SPACE


func _ready() -> void:
	toggle_mode = true
	set_event_from_shortcut(get_shortcut())
	add_input_action()


func _process(_delta: float) -> void:
	if action_name != "":
		var is_pressing := Input.is_action_pressed(action_name)
		var is_just_releasing := Input.is_action_just_released(action_name)
		button_pressed = is_pressing && !is_just_releasing


func set_event_from_shortcut(shortcut: Shortcut) -> void:
	if (shortcut):
		shortcut.events.resize(1)
		event = shortcut.get_events()[0]
	else:
		event = InputEventKey.new()
		event.physical_keycode = DEFAULT_EVENT_PHYSICAL_KEYCODE


func add_input_action() -> void:
	if action_name == "":
		action_name = "KEY_%s_%d" % [name, event.physical_keycode]

	if action_name != "" && !InputMap.has_action(action_name):
		InputMap.add_action(action_name)
		InputMap.action_add_event(action_name, event)

So which node(s) ? Or do you have any ressources i could watch/read to help myself plz :smiley: ?

There is a node which is known as GridContainer. You can use it for wrapping all keys in grid. You can read it for more information.

Thank you !!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.