I need some help here. I am developing a program that does 2-D computational fluid dynamics simulations using FTN95 and ClearWin+.

The computational routine is started as a call-back function to a user-selected menu item (created with %mn). This computational routine displays information (velocity, pressure, temperature, heat, etc) on a %gr graphics area.

Now I want to allow the user to interrupt this routine at any time. Ideally I would want it to be done by
a) pressing the ESC key, but
b) would settle for key+mouse button combination (say CTRL+MIDDLEBUTTON).

Inside the computational routine I would place some calls to

yield_program_control@(Y_TEMPORARILY)

and then process the events above (a or b). The second I know how to do it since I already have the %gr area opened with FULL_MOUSE_INPUT and there's a call-back function to deal with the mouse events. But how can I interrupt using the ESC key?

I know couple methods to run-pause-stop code which allow to do in parallel other things like realtime graphics and opening other menu items with working code doing other things.

One method is simple and almost perfect, but is not 100% reliable, while the second is 100% reliable but a bit too tricky to make a short demo out of my head, i am not quite getting its trick so i quickly forget it. I use both and will shortly describe them here. Now i am running out of time to search details but when time will allow i may find the demos.

Method 1. The GUI could be pretty complex and have hundreds callback for doing different things. If you will start all of callback functions with the Permit_another_callback@ then things go OK unless you by mistake hit the button several times too fast. Then this button will stop reacting. Rarely happening. And the amount of times another callbacks are permitted could be millions, no problems here. You can use buttons and radiobuttons and also in parallel the accelerator keys, by some reason they sometimes work when other fail. This method was promoted by Paul.

Method 2 needs short sample to show it. You create as usual the buttons (Run, Pause, Stop) with callback functions but the trick is to interrupt the source code of your GUI with additional subroutine which will have small part of the same GUI. This subroutine has to create window which will be permanently open during the run. All that looks like impossible even to comprehend but with the Clearwin this somehow works. Additional window can do nothing useful or do passively something like displaying elapsed CPU time, some menus etc. This method described me John Appleyard from Polyhedron two decades ago and it is the most bulletproof as it never failed in its everyday torture. If urgent, you can ask him

I published small reproducers of two or even three of such methods few times in this forum in the past, so you can search this forum using my name and keywords "Permit_another_callback@", "Appleyard", "Run-Pause-Stop", "multitasking" etc