Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Nixxon on Fri 25/11/2016 09:16:42

Title: Help with key combination show GUI
Post by: Nixxon on Fri 25/11/2016 09:16:42
Hey gang,

Recently I've made myself a nice little cheat menu that quickly enables me to test certain portions of my game. I can set the initial visibility to true/false no dramas in the main menu. It works a charm.

However, often I forget to turn the GUI off when compiling and have subsequently had the yucky looking cheat GUi showing in the main menu when showing off my game.

I would like to somehow script the GUI to turn visible only when pressing a key combination (eg. Shift + Z + P) for instance. QUALITY OF LIFE.

I have been perusing the manual and the "IsKeyPressed" function is looking fruitful. I could place this in the repeatedly execute for that room (main menu).

I am to understand that this however, doesn't allow key combinations -

KEYCODE is one of the ASCII codes, with some limitations: since it tests the raw state of the key, you CANNOT pass the Ctrl+(A-Z) or Alt+(A-Z) codes (since they are key combinations). You can, however, use some extra codes which are listed at the bottom of the section.

Is there in fact a way to do this?? Any help greatly appreciated. :)
Title: Re: Help with key combination show GUI
Post by: Crimson Wizard on Fri 25/11/2016 09:27:23
You could try testing several keys altogether:
Code (ags) Select

if (IsKeyPressed(eKeyZ) && IsKeyPressed(eKeyP) && (IsKeyPressed(403) || IsKeyPressed(404))))


In case you did not know, && means logical and , || means logical or

403 and 404 are left shift and right shift respectively. I found this info in the manual ("ASCII code table" article), apparently they do not have named constants in AGS, but you may define them for convenience:

Code (ags) Select

// Somewhere in the global header
#define LEFT_SHIFT 403
#define RIGHT_SHIFT 404

// The key test code
if (IsKeyPressed(eKeyZ) && IsKeyPressed(eKeyP) && (IsKeyPressed(LEFT_SHIFT) || IsKeyPressed(RIGHT_SHIFT))))
Title: Re: Help with key combination show GUI
Post by: Slasher on Fri 25/11/2016 09:29:36
Example on key press(s) in Global
Code (ags) Select
if (keycode ==eKeyCtrlA) { // CTRL + A
    gTablet.Visible = true;
}


AGS KeyCode       Key         ASCII code
eKeyNone          none          0
eKeyCtrlA         Ctrl+A        1
eKeyCtrlB         Ctrl+B        2
eKeyCtrlC         Ctrl+C        3
eKeyCtrlD         Ctrl+D        4
eKeyCtrlE         Ctrl+E        5
eKeyCtrlF         Ctrl+F        6
eKeyCtrlG         Ctrl+G        7
eKeyCtrlH         Ctrl+H        8
eKeyCtrlI         Ctrl+I        9
eKeyCtrlJ         Ctrl+J       10
eKeyCtrlK         Ctrl+K       11
eKeyCtrlL         Ctrl+L       12
eKeyCtrlM         Ctrl+M       13
eKeyCtrlN         Ctrl+N       14
eKeyCtrlO         Ctrl+O       15
eKeyCtrlP         Ctrl+P       16
eKeyCtrlQ         Ctrl+Q       17
eKeyCtrlR         Ctrl+R       18
eKeyCtrlS         Ctrl+S       19
eKeyCtrlT         Ctrl+T       20
eKeyCtrlU         Ctrl+U       21
eKeyCtrlV         Ctrl+V       22
eKeyCtrlW         Ctrl+W       23
eKeyCtrlX         Ctrl+X       24
eKeyCtrlY         Ctrl+Y       25
eKeyCtrlZ         Ctrl+Z       26


Title: Re: Help with key combination show GUI
Post by: Nixxon on Fri 25/11/2016 22:27:28
Thanks guys, making a bit of sense now. I am having trouble implementing the code however.

Both instances I get a Parse error: unexpected 'if'.

I'm placing the code into the global header.
Title: Re: Help with key combination show GUI
Post by: Cassiebsg on Sat 26/11/2016 10:29:18
It's not suppose to go on the header, but on the script under the function called "on_key_press"
Title: Re: Help with key combination show GUI
Post by: Slasher on Sat 26/11/2016 11:19:34
'if' is used within a function as a condition of that function.

in your case:

on_key_press is the function (built into Global.asc)
if key(s) pressed is the condition


Title: Re: Help with key combination show GUI
Post by: Crimson Wizard on Sat 26/11/2016 13:20:59
@Nixxon, in your first post you said that you were going to put the key detection code into repeatedly execute of the room, so I figured I do not need to mention where to put it.
You may as well put the code in the on_key_press, but you still won't be able to check 3 keys combination using only "keycode" variable, you would still need to use IsKeyPressed to know if other keys are pressed (e.g. Shift key).
Title: Re: Help with key combination show GUI
Post by: Nixxon on Sun 27/11/2016 00:44:06
Really odd, I've replaced one of the lines in the // debug functions just as a start and it doesn't seem to to work at all.

No big deal, I might just make a small transparent UI somewhere I can click on to bring up the menu.

Code (ags) Select
  // DEBUG FUNCTIONS
  if (keycode == eKeyCtrlS)  Debug(0,0);  // Ctrl-S, give all inventory
  if (keycode == eKeyCtrlV)  Debug(1,0);  // Ctrl-V, version
  if (keycode == eKeyCtrlA)  gcheat.Visible = true;  // Ctrl-A, show cheat menu
  if (keycode == eKeyCtrlX)  Debug(3,0);  // Ctrl-X, teleport to room
  if (keycode == eKeyCtrlW && game.debug_mode)