我试图想办法在我的 Qt 应用程序中使用系统范围的热键。要与您一起检查消息,GetMessage
需要一个while()
循环。这会导致窗口锁定并被禁用,但仍会为每个热键处理功能。
如何以允许我ui
响应的方式同时运行 while 循环?
例子
#define MOD_NOREPEAT 0x4000
#define MOD_ALT 0x0001
#include "stdafx.h"
#include <QDebug>
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
RegisterHotKey(NULL,1,MOD_ALT | MOD_NOREPEAT,0x42);
RegisterHotKey(NULL,2,MOD_ALT | MOD_NOREPEAT,0x44);
QApplication a(argc, argv);
MainWindow w;
w.show();
MSG msg;
while(GetMessage(&msg,NULL,0,0)){
if (msg.message == WM_HOTKEY){
if (msg.wParam == 1) qDebug() << "Hot Key activated : ALT + B";
if (msg.wParam == 2) qDebug() << "Hot Key activated : ALT + D";
}
}
return a.exec();
}