New AG command AG_ISFOREGROUND (78) to test whether the current instance of A-Shell (or the ATE client) has foreground status (i.e. is the active app):
? tab(-10,AG_ISFOREGROUND);chr(127);
input "",FG
Returns 1 if in foreground, else 0.
Note that as a practical matter (to eliminate the need for an INPUT statement), you'll probably want to call this via the MX_AGWRAPPER command:
MAP1 IS'FG,B,1
xcall MIAMEX, MX_AGWRAPPER, AG_ISFOREGROUND, "", IS'FG