0 votes

I want to create an action say "moveup" when I press KEYW but I don't want to create it in the project settings is there any way to assign KEYW to action "moveup" in gdscript?

in Engine by (293 points)

1 Answer

0 votes
Best answer

Try this:

# create the action 'move_up' if not already
if not InputMap.has_action('move_up'):
    InputMap.add_action('move_up')

var event = InputEventKey.new()
event.scancode = KEY_W
InputMap.action_add_event('move_up', event)

Check out this Input Mapping demo for more advanced key mapping.

by (4,221 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.