0 votes

I want to print anything, if I press the 1 on the keyboard. I already know how to do it with a letter:

if Input.is_key_pressed(KEY_A):
       print("Hello")

But now I want to know how to do this with a number instead of A.

in Engine by (369 points)

1 Answer

+1 vote
Best answer

Change the KEY_A to KEY_ + number. For example: if Input.is_key_pressed(KEY_1)

For more inputs control, for example, print hello when number 1 OR 2 is pressed. Go to Project settings - Input Map, and you can create your own actions and what keys will trigger them. In code to check these actions: Input.action_pressed(YOURACTION)

by (809 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 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 webmaster@godotengine.org with your username.