InputMap not available in editor?

Godot Version

4.4.1

Question

It seems the input map is not available in editor, as in a @tool.
Does anyone know how to utilize the inputmap in the editor in a tool or something similar.
I do this instead…

if Input.is_key_pressed(KEY_ALT) and Input.is_key_pressed(KEY_R):

But it fires of course every frame. Not nice.

I want to do

if Input.is_action_just_pressed("editor_tool_action"):

but this will give me an error that “editor_tool_action” does not exist in the inputmap… WAHT???

The InputMap and ProjectSettings are not connected. When running the script in the editor (a @tool script) the InputMap will be the one from the editor not the one you set in ProjectSettings.

I don’t think there’s a good way add a new input action to the editor’s input map from a simple @tool script. You may need to make a plugin to do it. You’ll need to use InputMap.add_action() and InputMap.add_action_event() for that.

I think it might help if you backed up a bit and told us what you were trying to accomplish it might be helpful.

when i press the input action that i called SnapToGrid (set to alt + R) the selection should snap to a grid, and do “other” things.

But if an input is not in the input map, i cant get the “just pressed” event which only lasts for one frame even if you keep the button combo pressed in for hours.

so … instead of get_key_pressed, which fires every frame, i want to use similar to inputmaps which is more advanced in its query.

hmm ok,
i’ve never really understood why all KEY_XXX cant support “just_pressed” mechanics…

For the same reason you don’t want to use it now. The game would have to monitor every key_press 60 times a second.

Just create a plugin.gd script, and add a few lines:

@tool
extends EditorPlugin

func _enable_plugin() -> void:
	var alt_r_key = InputEventKey.new()
	alt_r_key.alt_pressed = true
	alt_r_key.keycode = KEY_R
	alt_r_key.physical_keycode = KEY_R
	alt_r_key.key_label = KEY_R
	InputMap.add_action("snap_to_grid")
	InputMap.add_action_event("snap_to_grid", )

func _disable_plugin() -> void:
	InputEvent.erase_action("snap_to_grid")
1 Like

ok i will try a plugin then. :grinning_face: :victory_hand:

I still dont understand, i guess to be able to pick up is_pressed thats the same. Just pressed would need godot to remember the last state of 104ish keys, but it wouldnt need to check more than it already does? Or is that in the woods?

You can make the “is just pressed” behavior yourself with a simple toggle switch, see below the code snippet from ChatGPT, as I’m on mobile and can’t properly write code here myself.

extends Node

var alt_r_was_pressed: bool = false

func _process(delta: float) -> void:
	var alt_pressed: bool = Input.is_key_pressed(Key.ALT)
	var r_pressed: bool = Input.is_key_pressed(Key.R)

	# Check if both keys are pressed, and it wasn't pressed in the last frame
	if alt_pressed and r_pressed and not alt_r_was_pressed:
		alt_r_was_pressed = true
		print("Alt + R just pressed")
	elif not (alt_pressed and r_pressed):
		alt_r_was_pressed = false

Please don’t use chatgpt. The key constants are KEY_ALT and KEY_R.

2 Likes

I know I know. Heheeeheheh

AI does not work well with GDScript. The reason for this is LLMs are fed the internet. They only know what the internet knows. I’ve been testing ChatGPT with various languages, including GDScript since it was first in beta back in the fall of '22. I’ve also run other models “fine tuned” for development. Last time I tried to use one was a week ago.

These models scrape this forum, reddit, stackexchange, etc and then turn answers to people’s questions on these forums as authoritative answers to questions. But they aren’t copying and pasting. They are regurgitating linked objects in a database in their own words. It is literally like playing a game of telephone with a database that was created by an algorithm - not a human.

They are also usually taking the first answer to a question in a thread, ignoring any additional posts or corrections. I’ve literally googled things the AI couldn’t help me with and found where the AI got the answer to my question, along with clarifications ore replies saying it didn’t work below.

It also has no knowledge of versions of GDScript versions, including changes in syntax over time.

It also just makes stuff up, as @paintsimmon pointed out. It will tell you that things exist which straight up do not.

1 Like

Same. Gpt really doesn’t give usable answers. They range from ‘needs alot of corrections’ to ‘straight up nope’
Rarely. Raaaarely a 20 line regurgitation can make do with like 5 lines of edits by me. Never below that.

1 Like

Which has resulted in not using it at all any more. It just disappoints all the time, and I like the challenge anyway. So.