ubuntu下codeblocks起步-按键响应
原创:http://blog.youkuaiyun.com/sendltd/archive/2007/08/27/1761218.aspx
本例实现功能:在Dialog中按下Ctrl+Alt+Q关闭对话框
第一步:在Dialog类中声明wxEVT_KEY_DOWN事件的响应函数(事件函数一定没有返回值,参数也就有讲究的,详细说明在http://www.wxwidgets.org/manuals/2.8.4/wx_eventhandlingoverview.html)
class MyDialog: publicwxDialog
{
DECLARE_DYNAMIC_CLASS( MyDialog )
DECLARE_EVENT_TABLE()
public:
///Constructors
MyDialog();
///Destructor
~MyDialog();
void OnKeyDown(wxKeyEvent& event);
};
第二步:将wxEVT_KEY_DOWN事件与响应函数OnKeyDown关联起来
BEGIN_EVENT_TABLE( MyDialog, wxDialog )
EVT_KEY_DOWN(MyDialog::OnKeyDown)
END_EVENT_TABLE()
第三步:实现函数
void MyDialog::OnKeyDown(wxKeyEvent&event)
{
intca=event.GetModifiers();
int code=event.GetKeyCode();
if (code=='Q'&&ca==wxMOD_ALTGR)
{
this->Close();
}
event.Skip();
}
帮助文档:
http://www.wxwidgets.org/manuals/2.8.4/wx_wxkeyevent.html
http://www.wxwidgets.org/manuals/2.8.4/wx_keymodifiers.html#keymodifiers