guys I have a simple problem that I need to fix for my godot game. So I have a button (In blue) which when pressed changes the keybind of the player from "W" to "Q". I am trying to do the same on the Down button but instead of using a predetermined key, I would like the user to type any key they like from their keyboard and that key to be used as the down key. Right now I am trying to print that specific only only since I know how to continue the code after that. However I am stuck right now. Can someone help me out with how I can read user's input via keyboard?
#Input mapping key help
22 messages · Page 1 of 1 (latest)
i haven't done this myself, but i'm guessing most of these tutorials https://www.youtube.com/results?search_query=godot+4+input+remapping would do the trick?
I have already searched those
no luck, eh?
about your specific question "how I can read user's input via keyboard?" are you just not able to detect when the user presses a key?
kinda here's what I managed to do so far
I have almost solved it but I am stuck here
as you can see on the console from :
"var key_pressed = InputEventKey.new()"
I get:
"Key_Pressed:InputEventKey: keycode=(Unset), mods=none, physical=false, pressed=false, echo=false"
Which is almost what I want
ok, so InputEventKey.new() will create a new, blank InputEventKey object, but event is already the InputEventKey object that i think you want, right?
meaning that this whole thing is null, it has no value, whereas a key with stored value looks like this:
"InputEventKey: keycode=81 (Q), mods=none, physical=false, pressed=false, echo=false"
also, reassigning a keycode to key_pressed is a little weird, because that changes the type of that variable
try printing event
and finally if I read user's input via this code : "key_pressed = event.keycode" I get a number (if I press "A" I get 65 as the value)
you were right!
I was so close to the result
thank you so much my friend
no prob 🙂 you don't even need to make a new variable called key_pressed
you can take out lines 83 and 84 and then replace the key_pressed in line 88 simple with event
thank you my friend
btw if I want to change the text of the button how do I do it?
This is my code so far: up_input_button.text = str(event)
nevermind found it
thank you again so so much