EVT_KEY_DOWN event problem

Hello. A very little program have problem. I am trying to catch a key press globally(http://wiki.wxwidgets.org/Catching_key_events_globally) event and i can not.
Using Code::Blocks on Ubuntu unity and wxXidgets.
Any idea?


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
class MyApp : public wxApp
{
public:
    virtual bool OnInit();
    void OnKeyDown(wxKeyEvent& ev);
private:
        DECLARE_EVENT_TABLE();
};

class MyFrame: public GUIFrame
{
public:
    MyFrame(wxFrame *frame);
    ~MyFrame();
private:
    virtual void OnClose(wxCloseEvent& event);
};

IMPLEMENT_APP(MyApp);

bool MyApp::OnInit()
{
    MyFrame* frame = new MyFrame(0L);
    frame->Maximize();
    frame->Show();
    return true;
}

void MyApp::OnKeyDown(wxKeyEvent& ev){
 wxMessageBox( wxT("test"));
}


BEGIN_EVENT_TABLE(MyApp,wxApp)
EVT_KEY_DOWN(MyApp::OnKeyDown)
END_EVENT_TABLE()

MyFrame::MyFrame(wxFrame *frame)
    : GUIFrame(frame)
{
    m_staticText1->SetLabel(L"my text");
}


MyFrame::~MyFrame()
{
}

void MyFrame::OnClose(wxCloseEvent &event)
{
    Destroy();
}





Last edited on
The link that you provided uses wxApp::FilterEvent() to catch a key press.

Maybe use something like the following in MyApp:
1
2
3
4
5
6
7
int FilterEvent(wxEvent& event) {
    if (event.GetEventType() == wxEVT_KEY_DOWN) {
        wxMessageBox(wxString::Format(wxT("%d"), ((wxKeyEvent &)event).GetKeyCode()), wxT("KeyCode"));
        return true;
    }
    return -1;
}
I just make a litle project, same in Ubuntu and windows xp
In xp run very well.
The same project, making from beggining, in Ubuntu there is not respond in key press.
So the problem is in OS or WXWidgets or in C::B?

here the code ...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <wx/app.h>

class runApp : public wxApp
{
    public:
        virtual bool OnInit();
};

#include "runApp.h"
#include "runMain.h"

IMPLEMENT_APP(runApp);

bool runApp::OnInit()
{
    
    runDialog* dlg = new runDialog(0L);
    
    dlg->Show();
    return true;
}


#include "runApp.h"



#include "GUIDialog.h"

class runDialog: public GUIDialog
{
    public:
        runDialog(wxDialog *dlg);
        ~runDialog();
    private:
        virtual void OnClose(wxCloseEvent& event);
        virtual void press(wxKeyEvent& event);
        DECLARE_EVENT_TABLE();
};

runDialog::runDialog(wxDialog *dlg)
    : GUIDialog(dlg)
{
}

runDialog::~runDialog()
{
}

void runDialog::OnClose(wxCloseEvent &event)
{
    Destroy();
}

void runDialog::press(wxKeyEvent& event){

wxMessageBox(wxT("test"));

}

BEGIN_EVENT_TABLE(runDialog,GUIDialog)
EVT_KEY_DOWN(runDialog::press)
END_EVENT_TABLE()
Last edited on
Topic archived. No new replies allowed.