? tab(-10, AG_ISFOREGROUND); chr(127);
input "",FG
AG_ISFOREGROUND (78) tests whether the current instance of A-Shell (or the ATE client) has foreground status (i.e. is the active app). It 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