Associating ESC key with dialog button

Skip to first unread message

Kenneth Porter

Oct 18, 2022, 3:57:06 PM10/18/22
I'm messing with the font size on a full-screen dialog over Remote
Desktop and the on-site user reports that the buttons to dismiss the
dialog at the bottom are off the bottom of the screen. Oops.

The dialog displays the running status of a worker thread and has two
"Stop" buttons at the bottom, one for a "graceful" stop and the other
for halting immediately (and possibly losing part of the latest
operation's data).

I'd like to allow use of the escape key as an "emergency stop" to invoke
the Stop Immediately button's function. What's the code magic to do that?

I'm using Bind in my dialog constructor:

&CycleStatusDialog::OnStopImmediately, this);

Igor Korot

Oct 18, 2022, 4:04:34 PM10/18/22
Hi, Kenneth,
I think SetEscapeId() is what you are looking for...

Thank you.

> --
> Please read before posting.
> ---
> You received this message because you are subscribed to the Google Groups "wx-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
> To view this discussion on the web visit

Kenneth Porter

Oct 18, 2022, 5:59:14 PM10/18/22
On 10/18/2022 1:04 PM, Igor Korot wrote:
> I think SetEscapeId() is what you are looking for...

I think I need to re-think this. That would invoke the Close handler
which hides the dialog and ends the modal loop.

When the user hits my dialog's Stop Immediately button, the handler sets
a flag in the worker thread to tell it to exit at the next opportunity
rather than wait for a major operation to complete. (Each API call to
the hardware driver checks this flag.) The thread posts a "thread done"
event to the dialog, which then closes the window, hiding it and ending
the modal loop.

So I think I really want to intercept the Escape key as an ordinary key
and vector it away from the default Close handler.

David Connet

Oct 18, 2022, 6:04:03 PM10/18/22
All you should need to do is bind to wxID_CANCEL and do what you need to
there. Binding to that will handle 'ESC', clicking the 'X'(close)
button, or the 'Cancel' button (if you have one). I think that will work
even if you haven't specifically created a Cancel button...


Reply all
Reply to author
0 new messages