From: T. Horsnell on
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)
{
}
From: Vadim Zeitlin on
On Wed, 07 May 2008 15:02:52 +0100 "T. Horsnell" <tsh(a)mrc-lmb.cam.ac.uk> wrote:

TH> I'm trying, and failing, to collect keypress events for a frame.

Frames are not meant to have focus. Create a child window in it and handle
these events in it.

Regards,
VZ

--
TT-Solutions: wxWidgets consultancy and technical support
http://www.tt-solutions.com/

From: T. Horsnell on
Vadim Zeitlin wrote:
> On Wed, 07 May 2008 15:02:52 +0100 "T. Horsnell" <tsh(a)mrc-lmb.cam.ac.uk> wrote:
>
> TH> I'm trying, and failing, to collect keypress events for a frame.
>
> Frames are not meant to have focus. Create a child window in it and handle
> these events in it.
>
> Regards,
> VZ
>

OK. Thank you.
T.