Input.GetKey("Alpha1") error, Noob question

Probably a simple answer. lol

if (Input.GetKey("left ctrl") && Input.GetKey("Alpha1"))
        {
            Debug.Log("1");
        }

There’s a list of key names that Unity recognizes near the bottom of this page. I’m not sure what “Alpha1” is, but it’s not on the list.

If you are trying to get an input that you defined in the input manager, you probably want to be using GetButton or GetAxis instead of GetKey.

@Antistone , Thx for reply bro, I got this from here “Unity - Scripting API: KeyCode”

Do you have a Direct Link?

I just wanted to do Ctrl+1 on keyboard

@Antistone , i got the same Error for

if (Input.GetKey("left ctrl") && Input.GetButton("Alpha1"))
        {
            Debug.Log("1");
        }

try

    if (Input.GetKey(KeyCode.LeftCtrol) && Input.GetKey(KeyCode.Alpha1)
            {
                Debug.Log("1");
            }

@Giovane , Thx for Reply

https://puu.sh/EtrEk/eab6c70680.png

https://puu.sh/EtrFT/f40daf79d1.png

Dont work :frowning:

1 Like

@Giovane

NVm FIXED!

THX BRO

https://puu.sh/EtrHD/0b2b668eb3.png

1 Like

it’s GetKey instead of GetButton, and you have to remove the " (i don’t know the name in english)

You’re welcome

@Giovane , @Antistone , Ok so the Error Is gone when I use the following Code, However, The Debug.Log doesnt trigger, furthermore, if I press Ctrl+1 in play mode, something weird happens with my camera view!

if (Input.GetKey("left ctrl") && Input.GetKey(KeyCode.Alpha1))
        {
            Debug.Log("1");
        }
using UnityEngine;

public class Test : MonoBehaviour
{
    void Update()
    {
        if (Input.GetKey(KeyCode.LeftControl) )
        {
            Debug.Log("LeftControl");
        }
        if (Input.GetKey(KeyCode.Alpha1) )
        {
            Debug.Log("Alpha1");
        }
        if (Input.GetKey(KeyCode.Alpha1) && Input.GetKey(KeyCode.LeftControl))
        {
            Debug.Log("LeftControl + Alpha1");
        }
    }
}

5075906--499112--thread.png

@ , Thx bro, I noticed However, It Only works if I hold “1” first then press “Ctrl”

I kinda need it the other way around. If I press Ctrl first it doesnt work for me. generally in RTS game for players to store units they press Ctrl first then the number

if (Input.GetKey("left ctrl") && Input.GetKey(KeyCode.Alpha1))
        {
            Debug.Log("1");
        }

        if (Input.GetKey(KeyCode.Alpha1) && Input.GetKey(KeyCode.LeftControl))
        {
            Debug.Log("LeftControl + Alpha1");
        }

https://puu.sh/Ets6S/0ca88418bf.png

Lol I just noticed that Ctrl+1 and Ctrl+2 changed between scene wind and game window

Use only what I gave you. Delete your string-based stuff, it is not working.
What I gave you should work every way around.
5075942--499118--thread.png

If you take a look at the numbers on the right side, I held the Left CTRL, then I hit the 1.

Oh, and don’t try it in Editor (or try it at least 2019.something) unless you have the Shortcuts feature and you can remove the CTRL-1 shortcut to switch to the Scene view.

@ ,

lol thx man, this forum is full of helpful ppl

1 Like

Both Functions work now after i removed those shortcuts