Detecting modifiers keys (alt, ctrl, shift, etc.)

Started by fratello Manu, Fri 12/11/2021 10:09:21

Previous topic - Next topic

fratello Manu

Hi everyone,

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

I'd need something like:

Code: ags
// 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!

Gilbert

Use IsKeyPressed() and check for the codes here.

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
if (IsKeyPressed(407))  //Alt key
  {//blah bla bla
    }

Crimson Wizard

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

SMF spam blocked by CleanTalk