2002-04-07 14:08:25 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: keyboard.cpp
|
2004-05-25 07:20:37 -04:00
|
|
|
// Purpose: Keyboard wxWidgets sample
|
2002-04-07 14:08:25 -04:00
|
|
|
// Author: Vadim Zeitlin
|
2008-06-07 11:24:49 -04:00
|
|
|
// Modified by: Marcin Wojdyr
|
2002-04-07 14:08:25 -04:00
|
|
|
// Created: 07.04.02
|
|
|
|
// Copyright: (c) 2002 Vadim Zeitlin
|
|
|
|
// Licence: wxWindows licence
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "wx/wxprec.h"
|
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
|
|
|
#pragma hdrstop
|
|
|
|
#endif
|
|
|
|
#ifndef WX_PRECOMP
|
|
|
|
#include "wx/wx.h"
|
|
|
|
#endif
|
|
|
|
|
2012-03-03 19:28:58 -05:00
|
|
|
#ifndef wxHAS_IMAGES_IN_RESOURCES
|
2009-02-07 20:01:00 -05:00
|
|
|
#include "../sample.xpm"
|
|
|
|
#endif
|
2002-04-07 14:08:25 -04:00
|
|
|
|
2013-03-21 18:37:06 -04:00
|
|
|
// IDs for menu items
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
QuitID = wxID_EXIT,
|
|
|
|
ClearID = wxID_CLEAR,
|
|
|
|
SkipHook = 100,
|
|
|
|
SkipDown,
|
|
|
|
|
|
|
|
// These IDs must be in the same order as MyFrame::InputKind enum elements.
|
|
|
|
IDInputCustom,
|
|
|
|
IDInputEntry,
|
|
|
|
IDInputText,
|
|
|
|
|
|
|
|
TestAccelA,
|
|
|
|
TestAccelCtrlA,
|
|
|
|
TestAccelEsc
|
|
|
|
};
|
|
|
|
|
2002-04-07 14:08:25 -04:00
|
|
|
// Define a new frame type: this is going to be our main frame
|
|
|
|
class MyFrame : public wxFrame
|
|
|
|
{
|
|
|
|
public:
|
2008-06-07 11:24:49 -04:00
|
|
|
MyFrame(const wxString& title);
|
2002-04-07 14:08:25 -04:00
|
|
|
|
|
|
|
private:
|
2008-06-07 11:24:49 -04:00
|
|
|
// event handlers
|
|
|
|
void OnQuit(wxCommandEvent& WXUNUSED(event)) { Close(true); }
|
|
|
|
void OnAbout(wxCommandEvent& event);
|
2009-12-17 11:44:22 -05:00
|
|
|
|
2013-03-21 18:37:06 -04:00
|
|
|
void OnInputWindowKind(wxCommandEvent& event);
|
2012-07-31 07:09:00 -04:00
|
|
|
|
2009-12-17 11:44:22 -05:00
|
|
|
void OnTestAccelA(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{ m_logText->AppendText("Test accelerator \"A\" used.\n"); }
|
|
|
|
void OnTestAccelCtrlA(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{ m_logText->AppendText("Test accelerator \"Ctrl-A\" used.\n"); }
|
|
|
|
void OnTestAccelEsc(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{ m_logText->AppendText("Test accelerator \"Esc\" used.\n"); }
|
|
|
|
|
2008-06-07 11:24:49 -04:00
|
|
|
void OnClear(wxCommandEvent& WXUNUSED(event)) { m_logText->Clear(); }
|
2011-12-01 19:50:12 -05:00
|
|
|
void OnSkipDown(wxCommandEvent& event) { m_skipDown = event.IsChecked(); }
|
|
|
|
void OnSkipHook(wxCommandEvent& event) { m_skipHook = event.IsChecked(); }
|
2009-12-17 11:44:22 -05:00
|
|
|
|
2011-12-01 19:50:12 -05:00
|
|
|
void OnKeyDown(wxKeyEvent& event)
|
|
|
|
{
|
|
|
|
LogEvent("KeyDown", event);
|
|
|
|
if ( m_skipDown )
|
|
|
|
event.Skip();
|
|
|
|
}
|
2008-06-07 11:24:49 -04:00
|
|
|
void OnKeyUp(wxKeyEvent& event) { LogEvent("KeyUp", event); }
|
2013-03-21 18:36:57 -04:00
|
|
|
void OnChar(wxKeyEvent& event) { LogEvent("Char", event); event.Skip(); }
|
2011-12-01 19:50:12 -05:00
|
|
|
void OnCharHook(wxKeyEvent& event)
|
|
|
|
{
|
2012-07-29 18:08:21 -04:00
|
|
|
// The logged messages can be confusing if the input window doesn't
|
|
|
|
// have focus so warn about this.
|
|
|
|
if ( !m_inputWin->HasFocus() )
|
|
|
|
{
|
|
|
|
m_logText->SetDefaultStyle(*wxRED);
|
|
|
|
m_logText->AppendText("WARNING: focus is not on input window, "
|
|
|
|
"non-hook events won't be logged.\n");
|
|
|
|
m_logText->SetDefaultStyle(wxTextAttr());
|
|
|
|
}
|
|
|
|
|
2011-12-01 19:50:12 -05:00
|
|
|
LogEvent("Hook", event);
|
|
|
|
if ( m_skipHook )
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
2008-06-07 11:24:49 -04:00
|
|
|
void OnPaintInputWin(wxPaintEvent& event);
|
2002-04-07 14:08:25 -04:00
|
|
|
|
2008-06-07 11:24:49 -04:00
|
|
|
void LogEvent(const wxString& name, wxKeyEvent& event);
|
2002-04-07 14:08:25 -04:00
|
|
|
|
2013-03-21 18:37:06 -04:00
|
|
|
// Set m_inputWin to either a new window of the given kind:
|
|
|
|
enum InputKind
|
|
|
|
{
|
|
|
|
Input_Custom, // Just a plain wxWindow
|
|
|
|
Input_Entry, // Single-line wxTextCtrl
|
|
|
|
Input_Text // Multi-line wxTextCtrl
|
|
|
|
};
|
|
|
|
|
|
|
|
void DoCreateInputWindow(InputKind inputKind);
|
2012-07-31 07:09:00 -04:00
|
|
|
|
2008-06-07 11:24:49 -04:00
|
|
|
wxTextCtrl *m_logText;
|
|
|
|
wxWindow *m_inputWin;
|
2011-12-01 19:50:12 -05:00
|
|
|
bool m_skipHook,
|
|
|
|
m_skipDown;
|
2002-04-07 14:08:25 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-06-07 11:24:49 -04:00
|
|
|
// Define a new application type, each program should derive a class from wxApp
|
|
|
|
class MyApp : public wxApp
|
2002-04-07 14:08:25 -04:00
|
|
|
{
|
|
|
|
public:
|
2008-06-07 11:24:49 -04:00
|
|
|
// 'Main program' equivalent: the program execution "starts" here
|
2014-03-29 20:02:23 -04:00
|
|
|
virtual bool OnInit() wxOVERRIDE
|
2002-04-07 14:08:25 -04:00
|
|
|
{
|
2008-06-07 11:24:49 -04:00
|
|
|
// create the main application window
|
|
|
|
new MyFrame("Keyboard wxWidgets App");
|
2002-04-07 14:08:25 -04:00
|
|
|
|
2008-06-07 11:24:49 -04:00
|
|
|
// If we returned false here, the application would exit immediately.
|
|
|
|
return true;
|
2002-04-07 14:08:25 -04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2004-05-25 07:20:37 -04:00
|
|
|
// Create a new application object: this macro will allow wxWidgets to create
|
2002-04-07 14:08:25 -04:00
|
|
|
// the application object during program execution (it's better than using a
|
|
|
|
// static object for many reasons) and also declares the accessor function
|
|
|
|
// wxGetApp() which will return the reference of the right type (i.e. MyApp and
|
|
|
|
// not wxApp)
|
|
|
|
IMPLEMENT_APP(MyApp)
|
|
|
|
|
2008-06-07 11:24:49 -04:00
|
|
|
|
2002-04-07 14:08:25 -04:00
|
|
|
// ============================================================================
|
|
|
|
// implementation
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
// frame constructor
|
2008-06-07 11:24:49 -04:00
|
|
|
MyFrame::MyFrame(const wxString& title)
|
|
|
|
: wxFrame(NULL, wxID_ANY, title),
|
|
|
|
m_inputWin(NULL),
|
2011-12-01 19:50:12 -05:00
|
|
|
m_skipHook(true),
|
|
|
|
m_skipDown(true)
|
2002-04-07 14:08:25 -04:00
|
|
|
{
|
2009-02-07 20:01:00 -05:00
|
|
|
SetIcon(wxICON(sample));
|
|
|
|
|
2002-04-07 14:08:25 -04:00
|
|
|
// create a menu bar
|
|
|
|
wxMenu *menuFile = new wxMenu;
|
2008-06-07 11:24:49 -04:00
|
|
|
|
|
|
|
menuFile->Append(ClearID, "&Clear log\tCtrl-L");
|
|
|
|
menuFile->AppendSeparator();
|
|
|
|
|
2009-12-17 11:44:22 -05:00
|
|
|
menuFile->Append(TestAccelA, "Test accelerator &1\tA");
|
|
|
|
menuFile->Append(TestAccelCtrlA, "Test accelerator &2\tCtrl-A");
|
|
|
|
menuFile->Append(TestAccelEsc, "Test accelerator &3\tEsc");
|
|
|
|
menuFile->AppendSeparator();
|
|
|
|
|
2011-12-01 19:50:12 -05:00
|
|
|
menuFile->AppendCheckItem(SkipHook, "Skip CHAR_HOOK event",
|
|
|
|
"Not skipping this event disables both KEY_DOWN and CHAR events"
|
|
|
|
);
|
|
|
|
menuFile->Check(SkipHook, true);
|
|
|
|
menuFile->AppendCheckItem(SkipDown, "Skip KEY_DOWN event",
|
|
|
|
"Not skipping this event disables CHAR event generation"
|
|
|
|
);
|
|
|
|
menuFile->Check(SkipDown, true);
|
2002-04-07 14:08:25 -04:00
|
|
|
menuFile->AppendSeparator();
|
|
|
|
|
2013-03-21 18:37:06 -04:00
|
|
|
menuFile->AppendRadioItem(IDInputCustom, "Use &custom control\tCtrl-C",
|
|
|
|
"Use custom wxWindow for input window"
|
|
|
|
);
|
|
|
|
menuFile->AppendRadioItem(IDInputEntry, "Use text &entry\tCtrl-E",
|
|
|
|
"Use single-line wxTextCtrl for input window"
|
|
|
|
);
|
|
|
|
menuFile->AppendRadioItem(IDInputText, "Use &text control\tCtrl-T",
|
|
|
|
"Use multi-line wxTextCtrl for input window"
|
2012-07-31 07:09:00 -04:00
|
|
|
);
|
|
|
|
menuFile->AppendSeparator();
|
|
|
|
|
2008-06-07 11:24:49 -04:00
|
|
|
menuFile->Append(QuitID, "E&xit\tAlt-X", "Quit this program");
|
2002-04-07 14:08:25 -04:00
|
|
|
|
|
|
|
// the "About" item should be in the help menu
|
|
|
|
wxMenu *menuHelp = new wxMenu;
|
2012-01-20 11:51:09 -05:00
|
|
|
menuHelp->Append(wxID_ABOUT, "&About\tF1", "Show about dialog");
|
2002-04-07 14:08:25 -04:00
|
|
|
|
|
|
|
// now append the freshly created menu to the menu bar...
|
|
|
|
wxMenuBar *menuBar = new wxMenuBar();
|
2008-06-07 11:24:49 -04:00
|
|
|
menuBar->Append(menuFile, "&File");
|
|
|
|
menuBar->Append(menuHelp, "&Help");
|
2002-04-07 14:08:25 -04:00
|
|
|
|
|
|
|
// ... and attach this menu bar to the frame
|
|
|
|
SetMenuBar(menuBar);
|
|
|
|
|
2013-03-21 18:37:06 -04:00
|
|
|
DoCreateInputWindow(Input_Custom);
|
2008-06-07 11:24:49 -04:00
|
|
|
|
|
|
|
wxTextCtrl *headerText = new wxTextCtrl(this, wxID_ANY, "",
|
|
|
|
wxDefaultPosition, wxDefaultSize,
|
|
|
|
wxTE_READONLY);
|
|
|
|
headerText->SetValue(
|
|
|
|
" event key KeyCode mod UnicodeKey "
|
2012-07-24 16:45:52 -04:00
|
|
|
" RawKeyCode RawKeyFlags Position");
|
2008-06-07 11:24:49 -04:00
|
|
|
|
|
|
|
|
2009-02-07 20:01:00 -05:00
|
|
|
m_logText = new wxTextCtrl(this, wxID_ANY, "",
|
2008-06-07 11:24:49 -04:00
|
|
|
wxDefaultPosition, wxDefaultSize,
|
2012-07-29 18:08:21 -04:00
|
|
|
wxTE_MULTILINE|wxTE_READONLY|wxTE_RICH|wxHSCROLL);
|
2008-06-07 11:24:49 -04:00
|
|
|
|
|
|
|
// set monospace font to have output in nice columns
|
2009-02-07 20:01:00 -05:00
|
|
|
wxFont font(10, wxFONTFAMILY_TELETYPE,
|
2008-06-07 11:24:49 -04:00
|
|
|
wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
|
|
|
|
headerText->SetFont(font);
|
|
|
|
m_logText->SetFont(font);
|
|
|
|
|
|
|
|
// layout
|
|
|
|
wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
|
|
|
|
sizer->Add(m_inputWin, wxSizerFlags().Expand());
|
|
|
|
sizer->Add(headerText, wxSizerFlags().Expand());
|
|
|
|
sizer->Add(m_logText, wxSizerFlags(1).Expand());
|
|
|
|
SetSizerAndFit(sizer);
|
|
|
|
|
|
|
|
// set size and position on screen
|
|
|
|
SetSize(700, 340);
|
|
|
|
CentreOnScreen();
|
|
|
|
|
|
|
|
// connect menu event handlers
|
|
|
|
|
2013-04-25 06:11:03 -04:00
|
|
|
Connect(QuitID, wxEVT_MENU,
|
2008-06-07 11:24:49 -04:00
|
|
|
wxCommandEventHandler(MyFrame::OnQuit));
|
|
|
|
|
2013-04-25 06:11:03 -04:00
|
|
|
Connect(wxID_ABOUT, wxEVT_MENU,
|
2008-06-07 11:24:49 -04:00
|
|
|
wxCommandEventHandler(MyFrame::OnAbout));
|
|
|
|
|
2013-04-25 06:11:03 -04:00
|
|
|
Connect(ClearID, wxEVT_MENU,
|
2008-06-07 11:24:49 -04:00
|
|
|
wxCommandEventHandler(MyFrame::OnClear));
|
|
|
|
|
2013-04-25 06:11:03 -04:00
|
|
|
Connect(SkipHook, wxEVT_MENU,
|
2011-12-01 19:50:12 -05:00
|
|
|
wxCommandEventHandler(MyFrame::OnSkipHook));
|
2013-04-25 06:11:03 -04:00
|
|
|
Connect(SkipDown, wxEVT_MENU,
|
2011-12-01 19:50:12 -05:00
|
|
|
wxCommandEventHandler(MyFrame::OnSkipDown));
|
2008-06-07 11:24:49 -04:00
|
|
|
|
2013-04-25 06:11:03 -04:00
|
|
|
Connect(IDInputCustom, IDInputText, wxEVT_MENU,
|
2013-03-21 18:37:06 -04:00
|
|
|
wxCommandEventHandler(MyFrame::OnInputWindowKind));
|
2012-07-31 07:09:00 -04:00
|
|
|
|
2013-04-25 06:11:03 -04:00
|
|
|
Connect(TestAccelA, wxEVT_MENU,
|
2009-12-17 11:44:22 -05:00
|
|
|
wxCommandEventHandler(MyFrame::OnTestAccelA));
|
|
|
|
|
2013-04-25 06:11:03 -04:00
|
|
|
Connect(TestAccelCtrlA, wxEVT_MENU,
|
2009-12-17 11:44:22 -05:00
|
|
|
wxCommandEventHandler(MyFrame::OnTestAccelCtrlA));
|
|
|
|
|
2013-04-25 06:11:03 -04:00
|
|
|
Connect(TestAccelEsc, wxEVT_MENU,
|
2009-12-17 11:44:22 -05:00
|
|
|
wxCommandEventHandler(MyFrame::OnTestAccelEsc));
|
|
|
|
|
2011-12-01 19:50:12 -05:00
|
|
|
// notice that we don't connect OnCharHook() to the input window, unlike
|
|
|
|
// the usual key events this one is propagated upwards
|
|
|
|
Connect(wxEVT_CHAR_HOOK, wxKeyEventHandler(MyFrame::OnCharHook));
|
|
|
|
|
|
|
|
// status bar is useful for showing the menu items help strings
|
|
|
|
CreateStatusBar();
|
|
|
|
|
2008-06-07 11:24:49 -04:00
|
|
|
// and show itself (the frames, unlike simple controls, are not shown when
|
|
|
|
// created initially)
|
|
|
|
Show(true);
|
2002-04-07 14:08:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// event handlers
|
|
|
|
|
|
|
|
void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
2008-06-07 11:24:49 -04:00
|
|
|
wxMessageBox("Demonstrates keyboard event processing in wxWidgets\n"
|
|
|
|
"(c) 2002 Vadim Zeitlin\n"
|
|
|
|
"(c) 2008 Marcin Wojdyr",
|
|
|
|
"About wxWidgets Keyboard Sample",
|
|
|
|
wxOK | wxICON_INFORMATION, this);
|
2002-04-07 14:08:25 -04:00
|
|
|
}
|
|
|
|
|
2013-03-21 18:37:06 -04:00
|
|
|
void MyFrame::DoCreateInputWindow(InputKind inputKind)
|
2012-07-31 07:09:00 -04:00
|
|
|
{
|
|
|
|
wxWindow* const oldWin = m_inputWin;
|
|
|
|
|
2013-03-21 18:37:06 -04:00
|
|
|
switch ( inputKind )
|
|
|
|
{
|
|
|
|
case Input_Custom:
|
|
|
|
m_inputWin = new wxWindow(this, wxID_ANY,
|
|
|
|
wxDefaultPosition, wxSize(-1, 50),
|
|
|
|
wxRAISED_BORDER);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Input_Entry:
|
|
|
|
m_inputWin = new wxTextCtrl(this, wxID_ANY, "Press keys here");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Input_Text:
|
|
|
|
m_inputWin = new wxTextCtrl(this, wxID_ANY, "Press keys here",
|
|
|
|
wxDefaultPosition, wxSize(-1, 50),
|
|
|
|
wxTE_MULTILINE);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-07-31 07:09:00 -04:00
|
|
|
m_inputWin->SetBackgroundColour(*wxBLUE);
|
|
|
|
m_inputWin->SetForegroundColour(*wxWHITE);
|
|
|
|
|
|
|
|
// connect event handlers for the blue input window
|
|
|
|
m_inputWin->Connect(wxEVT_KEY_DOWN, wxKeyEventHandler(MyFrame::OnKeyDown),
|
|
|
|
NULL, this);
|
|
|
|
m_inputWin->Connect(wxEVT_KEY_UP, wxKeyEventHandler(MyFrame::OnKeyUp),
|
|
|
|
NULL, this);
|
|
|
|
m_inputWin->Connect(wxEVT_CHAR, wxKeyEventHandler(MyFrame::OnChar),
|
|
|
|
NULL, this);
|
|
|
|
|
2013-03-21 18:37:06 -04:00
|
|
|
if ( inputKind == Input_Custom )
|
2012-07-31 07:09:00 -04:00
|
|
|
{
|
|
|
|
m_inputWin->Connect(wxEVT_PAINT,
|
|
|
|
wxPaintEventHandler(MyFrame::OnPaintInputWin),
|
|
|
|
NULL, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( oldWin )
|
|
|
|
{
|
|
|
|
GetSizer()->Replace(oldWin, m_inputWin);
|
|
|
|
Layout();
|
|
|
|
delete oldWin;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-21 18:37:06 -04:00
|
|
|
void MyFrame::OnInputWindowKind(wxCommandEvent& event)
|
2012-07-31 07:09:00 -04:00
|
|
|
{
|
2013-03-21 18:37:06 -04:00
|
|
|
DoCreateInputWindow(
|
|
|
|
static_cast<InputKind>(event.GetId() - IDInputCustom)
|
|
|
|
);
|
2012-07-31 07:09:00 -04:00
|
|
|
}
|
|
|
|
|
2008-06-07 11:24:49 -04:00
|
|
|
void MyFrame::OnPaintInputWin(wxPaintEvent& WXUNUSED(event))
|
2002-04-07 14:08:25 -04:00
|
|
|
{
|
2008-06-07 11:24:49 -04:00
|
|
|
wxPaintDC dc(m_inputWin);
|
|
|
|
dc.SetTextForeground(*wxWHITE);
|
|
|
|
wxFont font(*wxSWISS_FONT);
|
|
|
|
font.SetWeight(wxFONTWEIGHT_BOLD);
|
|
|
|
font.SetPointSize(font.GetPointSize() + 2);
|
|
|
|
dc.SetFont(font);
|
|
|
|
|
2009-02-07 20:01:00 -05:00
|
|
|
dc.DrawLabel("Press keys here",
|
2008-06-07 11:24:49 -04:00
|
|
|
m_inputWin->GetClientRect(), wxALIGN_CENTER);
|
2002-04-07 14:08:25 -04:00
|
|
|
}
|
|
|
|
|
2002-04-07 17:02:10 -04:00
|
|
|
|
2008-06-07 11:24:49 -04:00
|
|
|
// helper function that returns textual description of wx virtual keycode
|
|
|
|
const char* GetVirtualKeyCodeName(int keycode)
|
2002-04-07 14:08:25 -04:00
|
|
|
{
|
2008-06-07 11:24:49 -04:00
|
|
|
switch ( keycode )
|
2002-04-07 14:08:25 -04:00
|
|
|
{
|
2008-06-07 11:24:49 -04:00
|
|
|
#define WXK_(x) \
|
2009-02-07 20:01:00 -05:00
|
|
|
case WXK_##x: return #x;
|
2008-06-07 11:24:49 -04:00
|
|
|
|
|
|
|
WXK_(BACK)
|
|
|
|
WXK_(TAB)
|
|
|
|
WXK_(RETURN)
|
|
|
|
WXK_(ESCAPE)
|
|
|
|
WXK_(SPACE)
|
|
|
|
WXK_(DELETE)
|
|
|
|
WXK_(START)
|
|
|
|
WXK_(LBUTTON)
|
|
|
|
WXK_(RBUTTON)
|
|
|
|
WXK_(CANCEL)
|
|
|
|
WXK_(MBUTTON)
|
|
|
|
WXK_(CLEAR)
|
|
|
|
WXK_(SHIFT)
|
|
|
|
WXK_(ALT)
|
|
|
|
WXK_(CONTROL)
|
|
|
|
WXK_(MENU)
|
|
|
|
WXK_(PAUSE)
|
|
|
|
WXK_(CAPITAL)
|
|
|
|
WXK_(END)
|
|
|
|
WXK_(HOME)
|
|
|
|
WXK_(LEFT)
|
|
|
|
WXK_(UP)
|
|
|
|
WXK_(RIGHT)
|
|
|
|
WXK_(DOWN)
|
|
|
|
WXK_(SELECT)
|
|
|
|
WXK_(PRINT)
|
|
|
|
WXK_(EXECUTE)
|
|
|
|
WXK_(SNAPSHOT)
|
|
|
|
WXK_(INSERT)
|
|
|
|
WXK_(HELP)
|
|
|
|
WXK_(NUMPAD0)
|
|
|
|
WXK_(NUMPAD1)
|
|
|
|
WXK_(NUMPAD2)
|
|
|
|
WXK_(NUMPAD3)
|
|
|
|
WXK_(NUMPAD4)
|
|
|
|
WXK_(NUMPAD5)
|
|
|
|
WXK_(NUMPAD6)
|
|
|
|
WXK_(NUMPAD7)
|
|
|
|
WXK_(NUMPAD8)
|
|
|
|
WXK_(NUMPAD9)
|
|
|
|
WXK_(MULTIPLY)
|
|
|
|
WXK_(ADD)
|
|
|
|
WXK_(SEPARATOR)
|
|
|
|
WXK_(SUBTRACT)
|
|
|
|
WXK_(DECIMAL)
|
|
|
|
WXK_(DIVIDE)
|
|
|
|
WXK_(F1)
|
|
|
|
WXK_(F2)
|
|
|
|
WXK_(F3)
|
|
|
|
WXK_(F4)
|
|
|
|
WXK_(F5)
|
|
|
|
WXK_(F6)
|
|
|
|
WXK_(F7)
|
|
|
|
WXK_(F8)
|
|
|
|
WXK_(F9)
|
|
|
|
WXK_(F10)
|
|
|
|
WXK_(F11)
|
|
|
|
WXK_(F12)
|
|
|
|
WXK_(F13)
|
|
|
|
WXK_(F14)
|
|
|
|
WXK_(F15)
|
|
|
|
WXK_(F16)
|
|
|
|
WXK_(F17)
|
|
|
|
WXK_(F18)
|
|
|
|
WXK_(F19)
|
|
|
|
WXK_(F20)
|
|
|
|
WXK_(F21)
|
|
|
|
WXK_(F22)
|
|
|
|
WXK_(F23)
|
|
|
|
WXK_(F24)
|
|
|
|
WXK_(NUMLOCK)
|
|
|
|
WXK_(SCROLL)
|
|
|
|
WXK_(PAGEUP)
|
|
|
|
WXK_(PAGEDOWN)
|
|
|
|
WXK_(NUMPAD_SPACE)
|
|
|
|
WXK_(NUMPAD_TAB)
|
|
|
|
WXK_(NUMPAD_ENTER)
|
|
|
|
WXK_(NUMPAD_F1)
|
|
|
|
WXK_(NUMPAD_F2)
|
|
|
|
WXK_(NUMPAD_F3)
|
|
|
|
WXK_(NUMPAD_F4)
|
|
|
|
WXK_(NUMPAD_HOME)
|
|
|
|
WXK_(NUMPAD_LEFT)
|
|
|
|
WXK_(NUMPAD_UP)
|
|
|
|
WXK_(NUMPAD_RIGHT)
|
|
|
|
WXK_(NUMPAD_DOWN)
|
|
|
|
WXK_(NUMPAD_PAGEUP)
|
|
|
|
WXK_(NUMPAD_PAGEDOWN)
|
|
|
|
WXK_(NUMPAD_END)
|
|
|
|
WXK_(NUMPAD_BEGIN)
|
|
|
|
WXK_(NUMPAD_INSERT)
|
|
|
|
WXK_(NUMPAD_DELETE)
|
|
|
|
WXK_(NUMPAD_EQUAL)
|
|
|
|
WXK_(NUMPAD_MULTIPLY)
|
|
|
|
WXK_(NUMPAD_ADD)
|
|
|
|
WXK_(NUMPAD_SEPARATOR)
|
|
|
|
WXK_(NUMPAD_SUBTRACT)
|
|
|
|
WXK_(NUMPAD_DECIMAL)
|
|
|
|
WXK_(NUMPAD_DIVIDE)
|
2010-09-11 06:18:57 -04:00
|
|
|
|
|
|
|
WXK_(WINDOWS_LEFT)
|
|
|
|
WXK_(WINDOWS_RIGHT)
|
2011-08-24 07:19:43 -04:00
|
|
|
#ifdef __WXOSX__
|
|
|
|
WXK_(RAW_CONTROL)
|
|
|
|
#endif
|
2008-06-07 11:24:49 -04:00
|
|
|
#undef WXK_
|
2010-09-11 06:18:57 -04:00
|
|
|
|
2009-02-07 20:01:00 -05:00
|
|
|
default:
|
|
|
|
return NULL;
|
2002-04-07 14:08:25 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-07 11:24:49 -04:00
|
|
|
// helper function that returns textual description of key in the event
|
|
|
|
wxString GetKeyName(const wxKeyEvent &event)
|
2002-04-07 14:08:25 -04:00
|
|
|
{
|
2008-06-07 11:24:49 -04:00
|
|
|
int keycode = event.GetKeyCode();
|
|
|
|
const char* virt = GetVirtualKeyCodeName(keycode);
|
|
|
|
if ( virt )
|
|
|
|
return virt;
|
2010-09-11 06:18:47 -04:00
|
|
|
if ( keycode > 0 && keycode < 32 )
|
2008-06-07 11:24:49 -04:00
|
|
|
return wxString::Format("Ctrl-%c", (unsigned char)('A' + keycode - 1));
|
2010-09-11 06:18:47 -04:00
|
|
|
if ( keycode >= 32 && keycode < 128 )
|
2008-06-07 11:24:49 -04:00
|
|
|
return wxString::Format("'%c'", (unsigned char)keycode);
|
2010-09-11 06:18:57 -04:00
|
|
|
|
2008-04-28 07:09:20 -04:00
|
|
|
#if wxUSE_UNICODE
|
2010-09-11 06:18:57 -04:00
|
|
|
int uc = event.GetUnicodeKey();
|
|
|
|
if ( uc != WXK_NONE )
|
|
|
|
return wxString::Format("'%c'", uc);
|
2008-04-28 07:09:20 -04:00
|
|
|
#endif
|
2010-09-11 06:18:57 -04:00
|
|
|
|
|
|
|
return "unknown";
|
2008-06-07 11:24:49 -04:00
|
|
|
}
|
|
|
|
|
2002-04-07 14:08:25 -04:00
|
|
|
|
2008-06-07 11:24:49 -04:00
|
|
|
void MyFrame::LogEvent(const wxString& name, wxKeyEvent& event)
|
|
|
|
{
|
2002-04-07 17:02:10 -04:00
|
|
|
wxString msg;
|
2012-07-24 16:45:52 -04:00
|
|
|
// event key_name KeyCode modifiers Unicode raw_code raw_flags pos
|
2008-06-07 11:24:49 -04:00
|
|
|
msg.Printf("%7s %15s %5d %c%c%c%c"
|
|
|
|
#if wxUSE_UNICODE
|
|
|
|
"%5d (U+%04x)"
|
|
|
|
#else
|
|
|
|
" none "
|
|
|
|
#endif
|
|
|
|
#ifdef wxHAS_RAW_KEY_CODES
|
2010-09-11 06:18:47 -04:00
|
|
|
" %7lu 0x%08lx"
|
2008-06-07 11:24:49 -04:00
|
|
|
#else
|
|
|
|
" not-set not-set"
|
|
|
|
#endif
|
2012-07-24 16:45:52 -04:00
|
|
|
" (%5d,%5d)"
|
2008-06-07 11:24:49 -04:00
|
|
|
"\n",
|
2002-04-07 17:02:10 -04:00
|
|
|
name,
|
2008-06-07 11:24:49 -04:00
|
|
|
GetKeyName(event),
|
|
|
|
event.GetKeyCode(),
|
|
|
|
event.ControlDown() ? 'C' : '-',
|
|
|
|
event.AltDown() ? 'A' : '-',
|
|
|
|
event.ShiftDown() ? 'S' : '-',
|
2008-07-19 01:33:36 -04:00
|
|
|
event.MetaDown() ? 'M' : '-'
|
2008-06-07 11:24:49 -04:00
|
|
|
#if wxUSE_UNICODE
|
2008-07-19 01:33:36 -04:00
|
|
|
, event.GetUnicodeKey()
|
|
|
|
, event.GetUnicodeKey()
|
2008-06-07 11:24:49 -04:00
|
|
|
#endif
|
|
|
|
#ifdef wxHAS_RAW_KEY_CODES
|
2008-07-19 01:33:36 -04:00
|
|
|
, (unsigned long) event.GetRawKeyCode()
|
|
|
|
, (unsigned long) event.GetRawKeyFlags()
|
2008-06-07 11:24:49 -04:00
|
|
|
#endif
|
2012-07-24 16:45:52 -04:00
|
|
|
, event.GetX()
|
|
|
|
, event.GetY()
|
2008-06-07 11:24:49 -04:00
|
|
|
);
|
2002-04-07 17:02:10 -04:00
|
|
|
|
2008-06-07 11:24:49 -04:00
|
|
|
m_logText->AppendText(msg);
|
2002-04-07 14:08:25 -04:00
|
|
|
}
|
2008-06-07 11:24:49 -04:00
|
|
|
|
|
|
|
|