Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: fratello Manu on Fri 12/11/2021 10:09:21

Title: Detecting modifiers keys (alt, ctrl, shift, etc.)
Post by: fratello Manu on Fri 12/11/2021 10:09:21
Hi everyone,

is there a way to catch the modifiers keys pressing as stand-alone keys?

I'd need something like:

Code (ags) Select
// called when a key is pressed
function on_key_press(eKeyCode keycode)

    if (keycode == eKeyAlt) //
    { }

    else if (keycode == eKeyCtrl) //



Use case: I control my character with keyboard and I'd like to use Ctrl for looking, Alt for talking, Shift for pick up, etc...

Thanks!
Title: Re: Detecting modifiers keys (alt, ctrl, shift, etc.)
Post by: Gilbert on Fri 12/11/2021 10:41:38
Use IsKeyPressed() (https://www.adventuregamestudio.co.uk/manual/ags53.htm#IsKeyPressed) and check for the codes here (https://www.adventuregamestudio.co.uk/manual/ags84.htm#ASCIIcodes).

However, unlike the on_key_press() event which will be executed automatically whenever a (non-modifier) key is pressed you need to check this from time to time, say, putting the following in the repeatedly_execute() event to check it every game loop:
Code (ags) Select
if (IsKeyPressed(407))  //Alt key
  {//blah bla bla
    }
Title: Re: Detecting modifiers keys (alt, ctrl, shift, etc.)
Post by: Crimson Wizard on Fri 12/11/2021 14:14:35
Somehow it occured that there are still no constants for these special keys, so you got to use literal numbers as in Gilbert's example.

You may find them in this table (at the very bottom):
https://adventuregamestudio.github.io/ags-manual/ASCIIcodes.html