How to make keyboard controls

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Noob_Maker
:warning: Old Version Published before Godot 3 was released.

I’m not sure if this got asked already, but how do you make keyboard controls in general?
I have an idea on how the code for it might be like: “if left key is pressed, decrease the x value by 5” But I have no idea how to do it with GDScript. I also looked at the documentation and I couldn’t find anything about it. :confused:

:bust_in_silhouette: Reply From: ericdl

You can bind keys in the Input Map tab found in menu Scene–>Project Settings.

To bind a new action, type in a new Action name and click Add. Your action will be added to the list, click the plus sign ‘+’ next to it and add as many new key/button inputs for it as you need.

Several keys are bound by default, for example the left key is bound to ui_left. So to code your example “if left key is pressed, decrease the x value by 5”, you can monitor for an input event:

var x = 0


func _ready():
	set_process_input(true)


func _input(event):
	if event.is_action_pressed("ui_left"): x -= 5
    if event.is_action_pressed("ui_right"): x += 5
	
	print(str(x))

omg this is so helpful thank you so much!!! :slight_smile:

Noob_Maker | 2016-11-11 23:12

What about in C#?

anonymous | 2018-03-11 01:24