QT Embedded:如何生成ESC(Escape)、F1等键的事件
我正在 QT 中开发一个嵌入式软件,它使用 LIRC 来处理 RC(远程控制)按键。
我设法映射所有 RC 键,以便 directFB 获得如下按键:
00000000000011b7 00 MENU
00000000000011a7 00 EXIT
0000000000001193 00 RED
我创建了一个 QT 类,它使用套接字来获取 LIRC 键并通过 QApplication::postEvent 为所有其他 QT 小部件等生成 KeyPressEvents。 它适用于“常规”键,但不适用于模拟 ESC、F1、F2 和其他“特殊”键的键。
我可以使用信号和插槽使其工作(请在下面查看),但是,这很困难,因为我需要始终连接和断开活动 Windows(小部件)的信号。我不相信对此没有更好的解决方案。
有谁知道如何为这些特殊键生成事件?
下面是 LIRC 套接字处理程序方法的代码片段:
QKeyEvent *event = NULL;
int emitKey = 0;
if (strstr(code, "MENU"))
{
cout << "MENU";
event = new QKeyEvent(QEvent::KeyPress, Qt::Key_Menu, Qt::NoModifier, "Menu", 0);
emitKey = Qt::Key_Menu;
}
else if (strstr(code, "EXIT"))
{
cout << "EXIT";
event = new QKeyEvent(QEvent::KeyPress, Qt::Key_Escape, Qt::NoModifier, "Exit", 0);
emitKey = Qt::Key_Escape;
}
else if (strstr(code, "RED"))
{
cout << "RED";
event = new QKeyEvent(QEvent::KeyPress, Qt::Key_F1, Qt::NoModifier, "Red", 0);
emitKey = Qt::Key_F1;
}
// All other keys, including ...
if (event)
{
cout << ": POSTED!" << endl;
event->ignore();
QApplication::postEvent(this, event);
emit k_output(emitKey);
}
菜单键事件正在到达活动窗口的 keyEvent 方法。其他的(退出,红色)不是......
非常感谢您的帮助。
I'm working on an embedded software in QT that uses LIRC to handle RC (Remote Control) key presses.
I managed to map all the RC keys so directFB is getting keypresses like these:
00000000000011b7 00 MENU
00000000000011a7 00 EXIT
0000000000001193 00 RED
I've created a QT class that uses sockets to grab LIRC keys and generate KeyPressEvents through QApplication::postEvent for all the other QT widgets and alike.
It works fine for "regular" keys, but it is not working for keys that emulate the ESC, F1, F2 and other "special" keys.
I could make it work using signals and slots (check it bellow), however, it's a harsh since I need to connect and disconnect the signals for active Windows (Widgets) all the time. I refuse to believe there is no better solution for that.
Does anyone know how to generate events for those special keys?
Following a code snippet of the LIRC socket handler method:
QKeyEvent *event = NULL;
int emitKey = 0;
if (strstr(code, "MENU"))
{
cout << "MENU";
event = new QKeyEvent(QEvent::KeyPress, Qt::Key_Menu, Qt::NoModifier, "Menu", 0);
emitKey = Qt::Key_Menu;
}
else if (strstr(code, "EXIT"))
{
cout << "EXIT";
event = new QKeyEvent(QEvent::KeyPress, Qt::Key_Escape, Qt::NoModifier, "Exit", 0);
emitKey = Qt::Key_Escape;
}
else if (strstr(code, "RED"))
{
cout << "RED";
event = new QKeyEvent(QEvent::KeyPress, Qt::Key_F1, Qt::NoModifier, "Red", 0);
emitKey = Qt::Key_F1;
}
// All other keys, including ...
if (event)
{
cout << ": POSTED!" << endl;
event->ignore();
QApplication::postEvent(this, event);
emit k_output(emitKey);
}
The Menu key event is reaching the active window's keyEvent method. The others (EXIT, RED) is not...
Thanks very much for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 postEvent 中使用当前聚焦的小部件解决了这个问题。
我在 LIRC 配置中遇到了一些问题,生成了一些“不太正确”的密钥代码。
如果有人需要这方面的帮助,我很乐意提供帮助。
谢谢
The use of the current focused widget in the postEvent solves the problem.
I was having some issues in the LIRC configuration that was generating some "not that right" key codes.
If anyone need help on that, I'll be glad to help.
Thanks