x


What key was pressed?

Is there any way to determine what key was pressed? Basically, what I want to do is this...

if (Input.anyKeyDown) {
     Debug.Log(keypress);
}

where keypress is the key that was pressed. I am only interested in alpha numeric keys, so I know I can do this by mapping the A key to "A" in the input preferences, etc... and a total of 36 if checks for all possible alpha numeric keys, but it seems there should be an easier way to do this.

So far I haven't come up with anything :(

Any help would be appreciated.

Thanks, -Larry

more ▼

asked May 16 '10 at 10:38 PM

Larry Dietz gravatar image

Larry Dietz
472 8 13 22

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Use Input.inputString, and check that the chars are >= 'a' and <= 'z', and >= '0' and <= '9'.

more ▼

answered May 16 '10 at 10:56 PM

Eric5h5 gravatar image

Eric5h5
80.2k 41 132 519

Perfect. Exactly what I was looking for. Don't know how I missed that. Believe it or not, I actually went through the reference before posting this question :)

Thanks, -Larry

May 16 '10 at 11:29 PM Larry Dietz
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x953
x54

asked: May 16 '10 at 10:38 PM

Seen: 3268 times

Last Updated: May 16 '10 at 10:38 PM