A better help for on_key_press

Started by Monsieur OUXX, Tue 16/07/2024 12:25:17

Previous topic - Next topic

Monsieur OUXX

As AGS 4 cuts ties with old AGS features, should we get rid of the "old" on_key_press, and while doing it remove the old eKeyCtrlA, eKeyCtrlB, etc. ?

old way:
Code: ags
// Check that only Ctrl is pressed
void repeatedly_execute()
{
    if (IsKeyPressed(eKeyCtrlLeft)) { ... }
}

// Check that ctrl+A is pressed
void on_key_press(eKeycode keyCode) {
  if (keyCode == eKeyCtrlA) { ... }
}

New way

Code: ags
// Check that only Ctrl is pressed :
void on_key_press(eKeycode keyCode, optional int mod) {
  if (mod & eKeyModCtrl) { ... }
}

// Check that ctrl+A is pressed
void on_key_press(eKeycode keyCode, optional int mod) {
  if (keycode == eKeyA && (mod & eKeyModCtrl)) { ... }
}

See the help article of on_key_press for more details.

I'm adding a question mark because maybe those would still be useful do scripters who still brute-force key reading in their main loop?

Code: ags
void repeatedly_execute()
{
    if (IsKeyPressed(eKeyLeftCtrl)) { ... } // make the spaceship go pew pew
}

EDIT : yeah that last use case is definitely still valid for keeping eKeyLeftCtrl... Once again, writing a forum post made me walk myself through the process :-P

=====================

On a side note, I think the article could provide better examples :
Code: ags
//This checks if Ctrl was pressed : 
if (mod & eKeyModCtrl)

It could do with an example showing Ctrl+A instead of just Ctrl. I'm guessing most scripters are after that.
It could also do with an example of Ctrl+Alt+A as it is where the modifiers and the binary logic will shine
 

SMF spam blocked by CleanTalk