How to Detect when Esc or ?Cancel Are Pressed?

When a the cursor is on a given control field, I would like to skip the control’s TakeAccepted Embed Code when the operator presses with Esc or the ?Cancel button. What should I test for? “Self.Response=RequestCancelled” or something like that?

It’s not all that clear (to me) what you are asking. For example, I don’t understand how you could be “on” another control field and pressing the ?Cancel button at the same time…

Also, my understanding is that the AcceptAll loop happens when you press the OK button and the Windowmanager’s PostCompleted method is called. I don’t think that AcceptAll loop happens when you press escape or hit the cancel button. If what you need to do is to skip normal accept behaviour when you are in acceptall then you could frame your code in
if not 0{PROP:AcceptAll}…end .

Don’t know if that helps or not.

If the user has “touched” the control, then the accepted event is going to fire when focus moves off the control. Possibly, in your event:Accepted embed for the control you can look at KeyCode() and/or FOCUS(). It would take some experimentation to see exactly what the values are.
Do you have the debuger class from @MarkGoldberg? If so, there is a PrintEvent method of that class that will give you a lot of information when the events occur.

Alert Events come before Accepted. So one way would be on the CANCEL button to ALRT(MouseLeft) so that Event:AlertKey / PreAlertKey will come first and you can exit the form. You could also ALRT(EscKey) on the WINDOW and do similar.

There was a ClarionMag article about it. I was the author. I cannot seem to remember how to search Cmag, but usually @vitesse does.

1 Like

I remember there was a posting on the newsgroups, but I don’t recall an article.

When searching the newsgroups, I also came upon this mention for “IMM”, which I don’t remember seeing before:
image

I tested IMM on the Cancel Button and it would not work for me. IMM is documented for REPEAT. The ALRT method did work.

I had a field that showed a Message if it was Not “1” so I fill in “2” then press Cancel and want to Not see the Message.

IF AutoDet:GroupMember <> 1 THEN 
    Message('Group Member Accepted is not 1 ','Dev Test')
    SELECT(?)
    CYCLE
end  

On Cancel I added ALRT(MouseLeft) . I also had &L (Alt+L) setup to test normal pressing Cancel to see the Message.

BUTTON('Cance&l'),AT(213,284,45,16),USE(?Cancel),ALRT(MouseLeft),#SEQ(3)

In ?Cancel embed for EVENT:AlertKey check for Mouse Left and close the form (legacy style) before the Entry gets Accepted and can show the mesage.

IF KEYCODE()=MouseLeft THEN 
   LocalResponse = RequestCancelled 
   DO ProcedureReturn

Alternatively I tested having the Alert “Accept / Press” Cancel and that worked. I would think this would work for an ALRT(EscKey) on the Window.

IF KEYCODE()=MouseLeft THEN POST(EVENT:Accepted,?Cancel).
1 Like

?Cancel EVENT:Selecting process before ?touchedEntryField EVENT:Accepted

I am wondering if the article you are thinking of was

First Field, Required Field by Steven Parker
Published 2002-01-25

not by you Carl, but it does mention:

"It took a reminder from Jeff Slarve and Carl Barnes to get me back on track:
Alert key processing precedes all other field processing."

Anyway see attached article with thanks as always to Dave Harms for making ClarionMag articles freely available:

cmag-2002-01.pdf (683.0 KB)

if that is not the article you were referring to, perhaps give me a few more clues for searching and I will try again!

1 Like