Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: shaungaryevans on Tue 19/05/2009 23:34:34

Title: Can you create shortcuts keypress in your GUI?
Post by: shaungaryevans on Tue 19/05/2009 23:34:34
Hi,

I have made a GUI with a question followed by YES and NO buttons. normally you would have to click the buttons. Can you create a short key so if I pressed the Y key, the YES button will work, and the same with N for No. If yes, how would you go about it please?
Title: Re: Can you create shortcuts keypress in your GUI?
Post by: on Tue 19/05/2009 23:47:42
You can't have hotkeys by default, but a simple workaround would be to check if the GUI is visible and add something like this to your on_keypress. This allows you to have all sorts of "hotkeys", and GUIs can even use "the same" keys provided only one of them is visible at a time.


if (SomeGui.Visible)
    if (Hotkey X pressed) { do function }


Sorry for the pseudocode, but you can easily look up "visible" in the manual, and the on_keypress function in the main script is already full of helpful comments.
Title: Re: Can you create shortcuts keypress in your GUI?
Post by: shaungaryevans on Wed 20/05/2009 00:04:53
Thank you, will try it tomorrow, will let you know how I got on.
Title: Re: Can you create shortcuts keypress in your GUI?
Post by: shaungaryevans on Wed 20/05/2009 20:48:00
Thank you very much, the game is much quicker this way now. I had to adjust the code a bit to fit my game but it worked. Thanks
Title: Re: Can you create shortcuts keypress in your GUI?
Post by: shaungaryevans on Thu 21/05/2009 19:25:56
what is the keycode of enter (return) please?
Title: Re: Can you create shortcuts keypress in your GUI?
Post by: on Thu 21/05/2009 19:27:48
From the top of my head I'd say 103, but there's a list in the manual when you search "Appendixes: ASCII Code Table."
Title: Re: Can you create shortcuts keypress in your GUI?
Post by: shaungaryevans on Thu 21/05/2009 19:34:19
is the manual the help on the AGS software?
Title: Re: Can you create shortcuts keypress in your GUI?
Post by: Atelier on Thu 21/05/2009 19:41:18
Yes, it comes with AGS. Press F1 when you're working on your game and it will pop up.
Title: Re: Can you create shortcuts keypress in your GUI?
Post by: shaungaryevans on Thu 21/05/2009 19:43:34
I have tried finding the 'Appendixes: ASCII Code Table.' but I can't find it.
Title: Re: Can you create shortcuts keypress in your GUI?
Post by: shaungaryevans on Thu 21/05/2009 19:44:28
found it
Title: Re: Can you create shortcuts keypress in your GUI?
Post by: on Thu 21/05/2009 19:55:51
Great  ;) Is that "hotkey workaround" good enough, though? Depending on the amount of GUIs with hotkeys, I think there might be better solutions (slimmer code, and all that). If you just have a few GUIs, I'd say go with it.
Title: Re: Can you create shortcuts keypress in your GUI?
Post by: shaungaryevans on Thu 21/05/2009 20:22:45
Quote from: Ghost on Thu 21/05/2009 19:55:51
Great  ;) Depending on the amount of GUIs with hotkeys, I think there might be better solutions (slimmer code, and all that).

Yes, its great, is there another way of doing it then, if you got a lot of GUIs?
Title: Re: Can you create shortcuts keypress in your GUI?
Post by: on Thu 21/05/2009 20:46:07
Well, one *could* go and use some tracking system that is updated when GUIs are made visible/invisible, but I think that would only be useful if you really are using a great deal of different GUIs with many different hotkeys. If there are only a few (like, say, half a dozen) your global script won't become too cluttered- and you can still set up different hotkey shemes and check against their owning GUIs with an if/then/else loop.

Like:

if (ReallyQuitGUI.Visible)
{if hotkey1...
if hotkey2...
} else if {StatusBarGUI.Visible)
{if hotkey1...
}

and so on. Sometimes a down'n'dirty approach is just enough  ;) (Though I'm going to take cover now)