wxGetKeyState()在Wayland环境下的功能异常问题求助
Wayland环境下wxGetKeyState()在窗口构造函数中检测异常的问题
在Wayland环境的Ubuntu 22.04中,使用wxWidgets 3.2.0时遇到wxGetKeyState()功能异常:我的应用会在顶级wxFrame窗口的构造函数中检测Shift键是否按下,若启动时Shift处于按下状态则运行诊断代码。这个功能在切换到Wayland前正常,且在同版本Ubuntu的X.org环境下仍能正常工作。
测试该问题只需在顶级wxFrame构造函数末尾添加以下代码:
MyFrame::MyFrame() { ... if (wxGetKeyState(WXK_SHIFT)) { wxMessageBox("Hello there"); } }
有没有人遇到过这个问题?有没有已知的解决方法?
编辑补充
运行下方最小测试应用后,得到X和Wayland环境下的不同结果:
X环境下按住Shift启动的输出:
18:40:25: Debug: from CTOR: 1 18:40:25: Debug: from idle: 1 18:40:25: Debug: from idle: 1 18:40:25: Debug: from idle: 1 18:40:25: Debug: from idle: 1 18:40:25: Debug: from idle: 1 18:40:25: Debug: from idle: 1 18:40:25: Debug: from idle: 1 18:40:25: Debug: from idle: 1 18:40:25: Debug: from idle: 1 18:40:25: Debug: from idle: 1 18:40:25: Debug: from idle: 1 18:40:25: Debug: from idle: 1 18:40:25: Debug: from idle: 1 18:40:25: Debug: from idle: 1 18:40:25: Debug: from idle: 1
X环境下wxGetKeyState()表现符合预期,16个空闲周期内均返回正确值。
Wayland环境下按住Shift启动的输出:
18:32:43: Debug: from CTOR: 0 18:32:43: Debug: from idle: 0 18:32:43: Debug: from idle: 0 18:32:43: Debug: from idle: 0 18:32:43: Debug: from idle: 1
Wayland环境下,构造函数中的检测失败,经过3个空闲周期后才返回正确值。
最小测试程序:
#include <wx/wx.h> class MyApp: public wxApp { public: virtual bool OnInit(); }; class MyFrame: public wxFrame { public: MyFrame(); void on_idle(wxIdleEvent& event); }; wxIMPLEMENT_APP(MyApp); bool MyApp::OnInit() { MyFrame* wnd = new MyFrame(); wnd->Show(); return true; } MyFrame::MyFrame() : wxFrame(NULL, wxID_ANY, "minimal") { Bind(wxEVT_IDLE, &MyFrame::on_idle, this); wxLogDebug("from CTOR: %d", wxGetKeyState(WXK_SHIFT)); } void MyFrame::on_idle(wxIdleEvent& event) { wxLogDebug("from idle: %d", wxGetKeyState(WXK_SHIFT)); }
内容的提问来源于stack exchange,提问作者Bob Enohp
相关产品推荐
相关产品推荐

