I
I
i__egor2021-10-09 20:08:37
Unity
i__egor, 2021-10-09 20:08:37

How to get the currently pressed key from the keyboard in unity?

as a string. if several at once, then several, or one character, or nothing. something like:string GetKeys()

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
Loli E1ON, 2021-10-10
@i__egor

private readonly Array keyCodes = Enum.GetValues(typeof(KeyCode));
 
void Update()
{
    if (Input.anyKeyDown)
    {
        foreach (KeyCode keyCode in keyCodes)
        {
            if (Input.GetKey(keyCode)) {
                Debug.Log("KeyCode down: " + keyCode);
            }
        }
    }
}

M
mustGamedev, 2021-10-09
@mustGamedev

Update()
{
 if(Input.GetKeyDown(KeyCode.Название клавиши)
 {
  //Сделать что то на определенную клавишу
 }
}

I am attaching a link to the documentation where there are all the answers to your questions: https://docs.unity3d.com/ScriptReference/Input.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question