Keyboard events from any key pressed

Hey guys :smile:

I’d like to be able to pick up when someone presses/ releases any key on the keyboard, just spamming Input.GetKey for every key seems a little extreme, and Event.current in OnGUI only ever runs once for a particular key then just ignores it after that (this might be a bug!)

function OnGUI() {
var e : Event = Event.current;
if (e.isKey){
print("detected "+e.keyCode);
}
}

If the same key is pressed more than once this doesnt pick it up at all, making it not too useful!

If anyone could give any advice on where to go I would be very grateful!

All the best,
Luke Briggs
KuleStar

Update: Input.AnyKey ignores the same button more than once, so I’m really thinking this is a bug!

function Update(){
if(Input.anyKeyDown){
        Debug.Log("You have pressed "+Input.inputString);
    }
}

If a key is pressed twice or more this only displays 1 log (must restart the game for it to log that key again!)

Check out Input.anyKey and Input.anyKeyDown

I think this is what you are looking for.

Hey! Thanks for the reply, just the problem is that they only pick up a key being pressed once then totally pack up! I’ve got a feeling it’s a bug, so I’ll report it later if it really isn’t suppost to work the way it is :slight_smile:

Hello there,
here is with what I came up with:

function Update () {
     if(Input.GetKey(KeyCode.P)||Input.GetKey(KeyCode.O)||Input.GetKey(KeyCode.U)||Input.GetKey(KeyCode.Y)||Input.GetKey(KeyCode.T)||Input.GetKey(KeyCode.R)||Input.GetKey(KeyCode.E)){
     transform.Rotate(0, 0,35 * Time.deltaTime);
    }
    else{
     transform.Rotate(0, 0,0 * Time.deltaTime);
    }
}

I only used the transform.Rotate as a test.
You just have to put in all off the keys,but wit copy and paste that should take less then 1-2 minut(s):slight_smile:
I guess this is not the correct way,but it works just fine;)
Please let me know…

Hey! Thanks for the reply :smile:

I was thinking of doing something like that just I wasn’t too sure how performance-ish it is! It would have to check about 40 keys for up or down every frame, which sounds like it could take quite long and drop out the frame rate. If worst comes to worst then I suppose it’s the only way that at least works!