Key presses in GUIs

Started by rich, Wed 17/03/2004 10:46:18

Previous topic - Next topic

rich

Hi, I am curious if there is a way to manipulate GUIs with key presses. What I want to do is make navigation possible in a GUI with the arrow keys and selection of the individual objects with the return/enter key or similar. I've looked everywhere and read nothing about this. Is it even possible?

I want to know because I'm preparing a template for my game which have a text parser system and I want it to be possible to do everything with the keyboard alone.
I'm so excited!

Radiant

Certainly. In your global script, find the function on_keypress () [sp?].
If you've started from the common template, this function will start with something like
Code: ags

if (IsGamePaused ()) return;


In front of this, add
Code: ags

if (IsGUIOn (My_GUI_1)) {
  if (keycode == 27) GUIOff (My_GUI_1); // escape key
  if (keycode == 13) ... // enter key
  // etc
}


rich

Yes, that makes sense. However, I guess I thought that the function on_key_press() was disabled when a GUI was turned on. Perhaps I'm confusing that with on_key_press being disabled when a GUI is turned on that has an enter text box... (which I use for Parsing). If that is the case, it won't be a problem since I'm using a pop-up GUI for text input that only appears when a letter key is hit. So, I think it will be okay. The trick is now, going to be highlighting the various buttons on a GUI, and worse the sliders, when the arrow keys are being pressed. I think I should be able to work it out. I'll draw a set of buttons, one that is highlighted and one that is not. Hmmm...
I'm so excited!

SSH

Its the "if (IsGamePaused ()) return;" that Radiant mentioned that stops keypresses being processed normally in that function, which is why it must go BEFORE that.
12

rich

Thanks, guys. Makes perfect sense.
I'm so excited!

SMF spam blocked by CleanTalk