PS … one must be careful, though… when doing this to dynamically change the GUI (i.e. you hit a key and some new areas pop up), it seems like the GUI system is having a problem with finding some references. I would assume this has to do with the multiple OnGUI calls during one frame (one for layout, one for “event-handling”… or maybe more).
My fix was to simply move those very specific cases back to the Update()-method (not very nice, but at least it works ).
… error is something like “Getting control 0’s position in a group with only 0 controls when doing keyDown”…
That looks like a cool idea, and interestingly, when I do add
Event.current.type == EventType.keyDown
the original problem is fixed. When I check EventType.repaint, however, the key stroke is not recognized. I can fix that by changing Input.GetKeyDown to Input.GetKey - however, then, even when using EventType.repaint, I’m getting the original problem.
Now, what really confuses me: I have these buttons spread over a few functions because the GUI has various states, depending on the selections. Interestingly, while the problem occured only in one particular instance before, which can be fixed by adding a check to “EventType.keyDown”, that same code messes everything up where it worked before by only checking “Input.GetKeyDown(…)”.
Is there any “proper” way of doing this? I think keyboard shortcuts for buttons are a rather nice thing to add, but at the moment the way I’m doing this feels kind of hackish
if (GUI.Button("[C]onfigure")
|| Event.current.Equals(Event.KeyboardEvent("c"))) {
isConfigurationScreen = true;
}
… doesn’t work for me, the same code works smoothly with Input.GetKeyDown and checking against Event.current.type == EventType.keyDown. It’s in an OnGUI() method.
@shaun: I would believe that this is “by design”. Capital letters are referred to by shift (#), so it should probably be Event.KeyboardEvent(“#m”)… I haven’t checked that, though, but the manual says it: