Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Akatosh on Mon 01/01/2007 13:48:48

Title: Trigger a Button_Click function when hitting enter [SOLVED]
Post by: Akatosh on Mon 01/01/2007 13:48:48
Right: I've got a textbox and an associated button next to it. Is there any other way to call the button_click function on hitting enter than trickstering around with the key_press function and if - Structures?
Title: Re: Trigger a Button_Click function when hitting enter
Post by: Ishmael on Thu 04/01/2007 10:01:28
I don't think there is, but it isn't a big deal...

if (keycode == 13) { // was enter, I think. Double-check that, though.
Ã,  if (gTextbox.Visible == true) {
Ã,  Ã,  button_click();
Ã,  }
}

You just need to make sure the button_click function is before the on_key_press function for this to work.
Title: Re: Trigger a Button_Click function when hitting enter
Post by: Ashen on Thu 04/01/2007 10:45:47
If there's a TextBox on the GUI, on_key_press AFAIK won't run - the TextBox claims all keypresses. Just call the Button's control function from the TextBox's, e.g.:

function btnText_Click(GUIControl *control, MouseButton button) {
  DoStuff();
}

function txtText_Activate(GUIControl *control) {
  btnText_Click(txtText, eMouseLeft);
}


It shouldn't matter what parameters you use when you call it, provided they're there.
Title: Re: Trigger a Button_Click function when hitting enter
Post by: Akatosh on Thu 04/01/2007 13:24:30
Thanks Ashen, my problem is solved  :)