Problem with input verificatoin and line edit

Godot Version



Hi. Sorry if i phrased this question in a confusing manner. I am having trouble remembering what this thing is called, which is part of why I’m asking here instead of keeping searching.

I am having a problem figuring out how to verify the input for a keybinding system. basically, I want to verify if the player hits a single character (ideally including white space, but lets start small). the goal is to make it so that the character hit can be used for a key to press an action, instead of the action is is by default bound to. basically, custom keybinds.

the error message I’m getting right now is that it cannot convert argument 2 form string to object. I understand that this means that the method ‘wants’ an object, but I am giving it a string. I’m not quite sure how to convert it to an object, however.

… I also still do need to do input checking.

I have a bit of a franken code at the moment, so bear with me, but here it is:

extends Control

var action_string

# Called when the node enters the scene tree for the first time.
func _ready():

func set_keys():
	for j in ACTIONS:
		if !InputMap.get_action_list(j).empty():
			#we need to get teh current assignemtns
			var temp_line_edit = get_node("Panel/ScrollContainer/VBoxContainer/HBoxContainer" + str(j) + "/" + str(j) + "LineEdit")
			#print ("Panel/ScrollContainer/VBoxContainer/HBoxContainer" + str(j) + "/" + str(j) + "LineEdit")
			#print (temp_line_edit)
func change_key(new_key):
	#delete key of pressed button
	if !InputMap.get_action_list(action_string).empty():
		InputMap.action_erase_event(action_string, InputMap.get_action_list(action_string)[0])
	#check if new key was assigned somewhere
	for i in ACTIONS:
		if InputMap.action_has_event(i, new_key):
			InputMap.action_erase_event(i, new_key)
	#add new key
	InputMap.action_add_event(action_string, new_key)

func _on_ATTACKButton_pressed():
	action_string = "ATTACK"
	#print ("I am changing the attack button bind")
	#the line edit is bieng null atm
	var line_edit = get_node("Panel/ScrollContainer/VBoxContainer/HBoxContainerINTERACT/LineEdit")
	print (line_edit)
	var key = line_edit.get_text()
	#line edit text is AWLAYS returning space that is werid right?
	print (key)

func _on_ATTACKLineEdit_text_changed(new_text):
	action_string = "ATTACK"

Let me know if I need to provide more information and I’d be glad to! thanks to anyone who can help!

Using a text input to get device keys is not how you should do this. Many textual inputs do not correspond to a single key, and some keys do not produce text (like shift).
You should just detect all unhandled keyboard events and use the first one you get as the new binding. That’s the simplest way to do it. Plus using the event keycode means InputMap will understand what you are trying to do.

Ah nods
Thank you for the information.
any advice on detecting unhandled keyboard events?
I’m kind of winging this so I’m not really sure what I’m doing here. sorry.

There is two functions you can override on any Node called _unhandled_input and _unhandled_key_input.
They receive the events that are not marked as handled by other controls.

ah, got it
thanks, ill look into that :slight_smile:

hi, sorry been a couple hectic days ^^;

you’re advice set me on the right track, I’m having another problem however, which is how to get the input event to be recognized as a keycode.

I can get the event to be human readable, which is nice for checking, but I figure there has to be a way to get it read as the computer sees it (in godot 3.5. lots of the information i find when googling now is for godot 4)

(if it’d be better to open a different thread with this, tahts fine, just let me know ^_^)

and…s orry to waste your time, was confused by the docs but i think I got it now


seems to b eworking

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