How do I trap a function code or a menu command that user has clicked?

In the GuiXT script for the screen you are interested in include an "ON" command.

Example:

On "fcode" "process=trap_enter.txt"

In above example script, when a user clicks the "fcode" on that particular screen, GuiXT will start executing an input script called trap_enter.txt. It is also possible to replace the command that user typed with something else

On "fcode" "process=trap_enter.txt" "Fcode=/nmm01"

In above example, when user clicks fcode, GuiXT will execute mm01 instead and start the input script named trap_enter.txt