A way to not divert ENTER to a textbox? (SOLVED)

Started by rich, Mon 04/04/2005 08:30:54

Previous topic - Next topic

rich

Hi, I have a GUI that I've set up that has a text box in it. I know how to code so that key presses are checked, even if a GUI is turned on. (Just do a if (keycode==..) before the check to see if the game is paused). By default, a text box will always divert keypresses that contain letters, spacebar, and enter to the textbox. In this case, on_key_press will never receive these keypresses. What I want to know is if there is a way to stop the diverting of an ENTER press to the text box. Why would I want to do this? I have created a custom Save window that I want to be manipulated by keypresses as well as using the mouse. All my GUIs that have no text boxes in them, I have no problem doing this. I use the arrow keys to move a highlighted box around to the different buttons... "save", "delete", cancel". Then, I want the Enter key to be able to press these buttons. Well, with the TextBox there, that's not possible because the Enter is diverted to it. I only want enter to effect the textbox if that textbox has been "highlighted" by my methods. Otherwise, I want the enter key to press the other highlighted buttons.

Any help on this issue, or a recommended workaround would be greatly appreciated!

Thanks,
Rich

EDIT: Works like a charm. Thank you. I didn't even need to send it on to on_key_press, just did it on_interface_click. If the textbox was "clicked", and one of the other buttons like "Delete" or "Cancel" was highlighted instead of "Save" I just did those. This was easier anyway, since I still want the mouse to be able to click the buttons. I didn't have to copy the code into on_key_press. Thanks!!!
I'm so excited!

Rui 'Trovatore' Pires

I don't know if you can possibly do this with your use of the textbox, but can you turn it off? In the new version of AGS, I believe you can switch it's "Visible" property; in earlier versions, you can put it in a GUI all by itself, superimpose it on the GUI you want, and turn it off when you don't want it to capture ENTER. REmember my text parser template? I did something similar. THAT's the reason I used a "fake" parser when the player pressed escape and accessed the menus, if I'd left the actual textbox it would still capture the ENTER key.
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

Radiant

A workaround might be to look in interface_click for that GUI textbox object, and have it 'post' a keypress for enter (e.g. it can call on_key_press)

Pumaman

I take it you want enter to work at the same time as the user can type into the textbox?

If not, you can just disable the textbox (set .Enabled property to false or use SetGUIObjectEnabled in 2.62) and it will no longer capture the keys.

If that's not what you want, a workaround would be as Radiant suggests, for example:

function interface_click(int interface, int button) {

Ã,  if ((interface == XXXX) && (button == YYYYY)) {
Ã,  Ã,  on_key_press(13);
Ã,  Ã,  return;
Ã,  }

...
}

where XXXX and YYYY is the text box's control id, obviously.

SMF spam blocked by CleanTalk