2013-11-22 5 views
2

Qt 애플리케이션에서 시스템 전체 핫키를 사용할 수있는 방법을 찾아 내려하고 있습니다. 메시지가 GetMessage인지 확인하려면 while() 루프가 필요합니다. 이로 인해 창을 잠그고 사용할 수 없게되지만 여전히 각 단축키에 대해 기능이 처리됩니다.전체 시스템 단축키 바로 가기 (Windows/Qt) : 창 잠금을 방지 하시겠습니까?

어떻게하면 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(); 
} 

답변

2

를 해결! terenty에 감사드립니다.

요약하면 ui로드를 완료 한 후 내 스레드로 메시지를 가져옵니다.

#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(); 

    QApplication::processEvents(); 

    MSG msg; 
    while(GetMessage(&msg,NULL,0,0)){ 
     TranslateMessage(&msg); 
     DispatchMessage(&msg); 
     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 msg.wParam; 
} 
+0

감사합니다.이 게시물에 너무 감사드립니다. Qt 및 Windows 응용 프로그램을 처음 사용하면서이 모든 것이 훌륭한 시간을 절약 해주었습니다. – dtc