Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: shaun9991 on Wed 26/06/2024 20:52:02

Title: Pressing Return key within a Textbox
Post by: shaun9991 on Wed 26/06/2024 20:52:02
Hi guys,

I've had a long time away from AGS and am super rusty - I'm using AGS 3.6.1.24 for the first time to play around with something - and I can't get the onkeypress function to work properly from within a textbox. I just want the player to be able to type their name and press the Return key, then the game moves on.

As an example, i've put this in globalscript on_key_press as I normally would (the textbox is included within gPassword)

if(gPassword.Visible == true)
  {
    if(keycode == eKeyReturn){
      //code here
      //eg
      Display("Done!");
    }


but instead of displaying "Done!", nothing happens. Am I doing something stupid? The keypresses work fine if a textbox is not displayed on the screen

Apologies, super rusty!
Shaun
Title: Re: Pressing Return key within a Textbox
Post by: Snarky on Wed 26/06/2024 21:43:34
TextBoxes eat all keypresses, so on_key_press is never called. Instead you have to use the TextBox.OnActivate event (from the event pane in the GUI editor).

Welcome back, BTW!
Title: Re: Pressing Return key within a Textbox
Post by: shaun9991 on Wed 26/06/2024 21:50:13
Ah of course!! Thank you Snarky :D