Nothing happens when I press the designed key to any action. I have checked my Input Map on the Project Settings menu: the name of the action is correct, the keyboard key is correct, yet anyway no matter what I do the code does not work! I’m new to this engine so I’m doing a very simple “input test” code. Can someone please explain how o fix it? I found a topic made by another user here with the same question (Mar 20) and he/she solved the problem simply by restarting Godot. I did the same, but it is still not working. Am doing smth wrong?
Here is the code:
extends Node2D
func _physics_process(delta: float) → void:
if(Input.is_action_just_pressed(“attack”)):
print(“Attack”)
The actions are case sensitive too, so make sure if you’re checking "attack", your input map doesn’t have it as "Attack". Though if you ask for an action it doesn’t know, I think it complains in the console.
Are you sure "attack" in the input map is hooked up to the key you think it is? There are various options like (for keyboard) physical key vs. scancode that might make the key you asked for different from the one you’re pressing.
Thanks for your answer. I’ve checked the name of the input and it is correct (also the console did not complain).
I tried to hook it to, for example, the space bar. I tried using all 3 options available [“physical key code (position on US QWERTY keyboard)”, “Keycode (Latin Equivalent”) and “Key Label (Unicode, Case-Insensitive)”] but yet none worked. I have even tried using the virtual keyboard, but still Godot did not recognize it.
Greetings and thanks for your suggestion. I did not understand it. I just add these lines literally to my code, or do I have to change “event” for the name of the action I’m trying to create on the input map?
"func _input(event):
if event is InputEventKey: print(event) "
Anyway, I tried to add exact these lines above to my code and it did not work. The output does not even register what key I am pressing, if that was the goal of your suggestion.
I even changed my Godot to 4.3.stable (the same version that the instructor of my online course is using) but it is still not working.
Perhaps is there any configuration I need to do to my physical keyboard (maybe through Control Panel) in order to fix this issue?
Hello! func _input(event) is a native function of Nodes. You don’t need to change the event as it’s a default variable and it gives you all the information of the current event that is happening. For more info about this, please read the Godot docs.
Anyway, try this instead:
func _input(event):
print(event)
This prints the information of any event that is happening currently. Do make sure that the node this script is in is in your current scene tree and is exposed to input events.
I know that many times the cause of an error or a bug is quite simple, but, yes, I indented the code, and “attack” is on the input map. Unfortunatelly, it is not that…
Hello,
I tried what you suggested, and it worked. Godot recognized the keys I pressed, and after a few trys it reconized the inputs I created on input map.
The problem was quite simple and very, very silly: the debug screen occupies my full screen and so I minimize it in order to see the output map. However, when it is minimized, it is as if I’m not playing the “game” anymore, and thus the inputs are not recognized as if in-game, which creates the “illusion” that Godot is not reading my inputs.
Thanks again for your time, baba.
It turned out the answer was simple and very, very silly: the debug screen occupies my full screen and so I minimize it in order to see the output map. However, when it is minimized, it is as if I’m not playing the “game” anymore, and thus the inputs are not recognized as if in-game, which creates the “illusion” that Godot is not reading my inputs.
Ah, I should have thought of this; if your game window doesn’t have focus, it doesn’t get keyboard input. My dev machine is running Linux and is set up for floating focus (that is, whatever window the mouse pointer is over has keyboard focus), so I’ve seen this happen many times. I run the game, but the mouse pointer is floating over the Godot window. Gamepad input works fine so everything seems to be working, but keyboard input goes to the Godot editor (or whatever the mouse happens to be over).