Welcome Guest, please login or register.
Username:
Password:

Pages: [1]
Topic Tools  
Read
March 03, 2010, 12:53:53 PM
amadis
Newbie
*
Offline Offline

Posts: 3



I'm trying to learn wxWidgets building my GUIs from wxFormBuilder (A great tool indeed) and C++.
This is my first post here, so I'm sorry if it's too "basic".

When I create a dialog that is opened from the main form, I'd like to add a feature to close it if ESC key is pressed. I used OnChar event in the dialog, but it seems the method to which the event should connect is not executed.
Does anybody knows about some examples on how to track key events?

Thanks,
Matías
Logged
 

Read
March 03, 2010, 02:11:17 PM
yohannbzh
Newbie
*
Offline Offline

Posts: 6



Use OnKeyDown (or OnKeyUp, as you want). After, in your method, you must verify if the key pressed is ESC.

Example in Python
Code:
    def OnKeyDown(self, e):
        if e.GetKeyCode() == wx.WXK_ESCAPE:
            ..... your code .....

Yohann
« Last Edit: March 03, 2010, 02:47:34 PM by yohannbzh » Logged
 

Read
March 03, 2010, 05:35:40 PM
amadis
Newbie
*
Offline Offline

Posts: 3



Yohann,

Thanks for your answer. I tried something similar but in C++ without luck:

Code:
void VDialogo::TeclaPres( wxKeyEvent& event )
{
    // my test code
}

(VDialog is the inherited class from the dialog class generated by wxFormBuilder).
I assume that the method should be called if any key is Pressed down. (I used OnKeyDown event and linked with "TeclaPres" name in the dialog design).
But the method seems not to be called anyway. I use the same approach with mouse clicks over buttons and works ok... I think if there's something related with focus ?

Logged
 

Read
March 03, 2010, 09:35:54 PM
amadis
Newbie
*
Offline Offline

Posts: 3



Well, I found a solution... May be is no the best.
By selecting button's IDs of the dialog and adding "SetFocus()" in dialog class constructor to focus on dialog.
That way if ESC is pressed the dialog closes.

But I'll keep on trying to find out why OnKeyDown event...
Logged
 

Pages: [1]
Jump to:  

Theme by webtechnica.net