- Home /
Turn Currently Held Button To A KeyCode(C#)
Hello Again Unity Answers! Im Back Yet Again For Another Question That IM SUre You Already Know(If You Read The Title), Here It Goes-
I Was Wondering If There Was A Way To Turn Any Currently Held Button Into A KeyCode. I Have Seen Ways To Turn Some Keys Into KeyCodes And That Is lIke This
void OnGUI() {
Event e = Event.current;
if(e.isKey) {
print(e.keyCode);
}
}
Yet That Only Returns Some Characters Which Dont Include Shift, CapsLock, Mouse Buttons And Possibly Others Im Unaware Of. I Want To Be Able To Turn Any Key Thats Pressed Down At All To Turn Into A KeyCode. If You Are Wondering, This Will Be Used For Custom Control Setup In My Game. My Last Idea Which as To Turn A Button To A String To Use With GetKeyDown Did Not Work, And This Is My New Idea. Thanks For Any Help Given!
Answer by Dracorat · Nov 12, 2013 at 08:57 PM
A) Please Don't Type In Mixed Case.
B) If you want to know whether a modifier key (such as shift etc) is being held along with the key in question, e.Modifiers
will tell you.
If I recall how modifiers works correctly, testing for shift is like:
if(e.modifiers && EventModifiers.Shift) { /*Shift was also pressed with this button*/ }
C) Pressing shift, etc should also have their own code.
D) More appropriate however, would be the use of Input.GetKeyDown
http://docs.unity3d.com/Documentation/ScriptReference/Input.GetKeyDown.html
For Answer Part D, Im Not Using It To Detect If The $$anonymous$$ey Is Being Held Down, Im Trying To Use It To Change A $$anonymous$$eyCode To The Button Im Holding Down At A Certain Time(In This Case, In The Options)
Please also consider his point A. It is a real pain to read your questions with your improper use of sentence casing. For the sake of people helping you, save yourself the trouble of pressing Shift for every single word. I, for one, would be more inclined to help you if reading your questions and comments wasn't such a chore.
It requires a lot of coding. Luckily someone has done the heavy lifting for you already...
http://forum.unity3d.com/threads/53726-Custom-Inputmanager-v1-4-VERY-easy-to-use-now-!
I have known about cInput for quite some time. Im just not sure about it since it changes the input asset in unity(im very overprotective of my computer :D)