as the header says…here the script, it shows all except shift keys, why?!
using UnityEngine;
using System.Collections;
public class RainInput : MonoBehaviour
{
public string event1;
void Update()
{
if (event1.Length > 0)
{
Debug.Log(event1);
}
event1 = "";
}
void OnGUI()
{
Event e = Event.current;
{
string tmpstr = "" + e.keyCode;
if (tmpstr == "None")
{
return;
}
event1 = tmpstr;
}
}
}
Because the Event class is ment for GUI key input quite similar to the windows char-messages. Shift, Ctrl and Alt are modifier keys so usually you don’t execute an action when pressing those keys. They change the behaviour of other keys.
To sum up:
-
Event class is used for GUI input
-
Input class is used to process any game input(including shift, alt, …).
- Event class can only be used in OnGUI
- Input class should only be used in Update or LateUpdate
edit
When using the event class you should always check the event type. Here you can see all possible events. Unity processes a lot events with OnGUI. It is called for each event. Usually 2 times per frame (Layout and Repaint event), but also for any kind of key or mouse event (the mouse move event only exists in the editor afaik).
void OnGUI()
{
Event e = Event.current;
if (e.type == EventType.KeyDown)
{
if (e.keyCode == KeyCode.A)
// ...
}
}
void Update()
{
if (Input.GetKeyDown(KeyCode.LeftShift ))
{
Debug.Log("LeftShift has been pressed");
}
}
Here’s the list of all key codes
Look at
Shift, Ctrl and Alt can be checked as event with this.