grabbing frame char events
T. Horsnell
tsh at mrc-lmb.cam.ac.uk
Wed May 7 07:02:52 PDT 2008
I'm trying, and failing, to collect keypress events for a frame.
Mouse-click events work OK. My simple test prog is shown below.
Should this work? Or would keypress events for the frame be being
intercepted elsewhere.
Thanks,
Terry
// Name: prog7.cpp
// Purpose: testing key+mouse events
#include "wx/wx.h"
// Declare the application class
class MyApp : public wxApp
{
public:
// Called on application startup
virtual bool OnInit();
};
// Declare our main frame class
class MyFrame : public wxFrame
{
public:
// Constructor
MyFrame(const wxString& title);
// Event handlers
void LeftDown(wxMouseEvent& event);
void KeyPress(wxKeyEvent& event);
private:
// This class handles events
DECLARE_EVENT_TABLE()
};
// Implements MyApp& GetApp()
DECLARE_APP(MyApp)
// Give wxWidgets the means to create a MyApp object
IMPLEMENT_APP(MyApp)
// Initialize the application
MyFrame *frame;
bool MyApp::OnInit()
{
#include "wx/button.h"
// Create the main application window
frame = new MyFrame(wxT("Minimal wxWidgets App"));
// Show it
frame->Show(true);
// Start the event loop
return true;
}
// Event table for MyFrame
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_LEFT_DOWN(MyFrame::LeftDown)
EVT_CHAR(MyFrame::KeyPress)
END_EVENT_TABLE()
void MyFrame::LeftDown(wxMouseEvent& event)
{
printf("Mouse coords: %d %d\n",(int)event.GetX(),(int)event.GetY());
}
void MyFrame::KeyPress(wxKeyEvent& event)
{
event.Skip();
printf("Keycode=%i\n",(int)event.GetKeyCode());
}
#include "mondrian.xpm"
MyFrame::MyFrame(const wxString& title)
: wxFrame(NULL, wxID_ANY, title)
{
}
More information about the wx-users
mailing list