#Input mapping key help

22 messages · Page 1 of 1 (latest)

civic basalt
#

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?

dense adder
dense adder
#

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?

civic basalt
#

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

dense adder
#

ok, so InputEventKey.new() will create a new, blank InputEventKey object, but event is already the InputEventKey object that i think you want, right?

civic basalt
#

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"

dense adder
#

also, reassigning a keycode to key_pressed is a little weird, because that changes the type of that variable

#

try printing event

civic basalt
#

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)

civic basalt
#

I was so close to the result

#

thank you so much my friend

dense adder
#

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

civic basalt
#

thank you my friend

civic basalt
#

nevermind found it

#

thank you again so so much