- Home /
How to check which key i have pressed?
i want to check which key i have pressed. So inside Debug.Log()… what should i write? If i am pressing K … K should come in the console window.
Answer by chelnok · May 08, 2013 at 01:21 PM
if(Input.anyKey)
{
Debug.Log(Input.inputString);
}
if i am writing Debug.Log(Input.inputString); and pressing $$anonymous$$.... in the console window it is co$$anonymous$$g $$anonymous$$ and 10 times blank debug.
interesting.. i havnt actually ever used that nothing but debugging reasons, and never thought it much more. I tried, and you are right about it. Sorry, dont know any other tricks, but check this one: http://answers.unity3d.com/questions/369542/retriving-double-index-from-input-string.html
Answer by SubatomicHero · May 08, 2013 at 11:10 AM
void Update()
{
if (Input.GetKeyUp("k"))
{
Debug.Log("K was pressed");
}
}
like this.
if(Input.any$$anonymous$$ey)
{
Debug.Log(); //Here i have to print which key was pressed
}
Answer by pgomes · Jul 08, 2014 at 04:39 PM
In certain cases you might want to use the following:
void OnGUI() {
Event e = Event.current;
if (e.isKey)
Debug.Log("e.keyCode: "+e.keyCode);
}
I was trying to understand the button output of a peripheral recognized as a keyboard (wireless presenter), and Input.inputString didn't help me because it was returning an empty string for non printable characters such as PageUp.
that works, however i get two log entry every time i press a key; one for the key, and another one "e.keyCode: None" ..just curious, any idea why? Some sort of reset event in background..?
Your answer
Follow this Question
Related Questions
Get numeric key 4 Answers
GetKey/GetButton not working if 2 Adjacent keys are being pressed at the same time 1 Answer
Is there a way to get precise input ? 1 Answer
key remaping menu 0 Answers