← Back to team overview

kicad-developers team mailing list archive

ESC key and dialogs


As you know, our UIpolicies.txt file says that the ESC key should dismiss a dialog window. The wxWidgets documentation says only that if you bind a button to the close process, and give that button the wxID_CANCEL id, then the ESC key will work. This is not sufficient, at least not on Linux with wxWidgets 2.8.4.

I have found that the keyboard focus must be set to one of the buttons in the dialog during the window creation process, and it seems not to matter which button. Here are the *additional* steps required to get the ESC key to work: (beyond using the *mandatory* wxID_CANCEL id for the button that closes the window upon a mouse click)

1) Using the DialogBlocks editor, load the *.pjd file, select the top dialog window

2) Click on the Event Handlers tab, and put a check mark into the first box, which should be wxEVT_INIT_DIALOG. This will create a function called OnInitDialog() in the dialog class.

3) Make sure at least one button has a given name (rather than an automatically generated name) by entering that name into the "Name" field associated with the button. Let's say that button name is, for example, m_CloseButton. Save the project and this regenerates the C++ code.

4) In the C++ code make sure your OnInitDialog() function has a line with the "SetFocus()" call, like this:

void dialog_freeroute_exchange::OnInitDialog( wxInitDialogEvent& event )
m_CloseButton->SetFocus(); // <----add this line

////@begin wxEVT_INIT_DIALOG event handler for ID_DIALOG_FREEROUTE_EXCHANGE in dialog_freeroute_exchange.
// Before editing this code, remove the block markers.
////@end wxEVT_INIT_DIALOG event handler for ID_DIALOG_FREEROUTE_EXCHANGE in dialog_freeroute_exchange.

Best Regards,


Follow ups