when pressing F3/F12 on a commandscreen the message CPF6801
will appear in the joblog. The msgdta will hold F3 or F12 in the first 3 characters. In a CL pgm you can monitor for this message and checking the msgdta the following way :
MONMSG MSGID(CPF6801) CMPDTA(F12) EXEC(***) where you can monitor also of course for F3 in the CMPDTA.
F3 and F12 are defined in CUA as Exit and Cancel. After the DSPUSRPRF (or most any system command or panel) returns, call the QUSRJOBI API with format JOBI0600. Check the receiver variable offset 102 for Exit and 103 for Cancel.