I have added an override to the key press event of my main widget:
Void MainWindow :: keyPressEvent (QKeyEvent * E) {If (e-> Key () == Qt :: Key_F11) {if (e->; modifiers () and Qt :: AltModifier & amp; E-& gt; Modifier () & amp; Qt :: ControlModifier} {// do stuff}}} The problem is that it does not work if I'm alone If I try AltModifier or ControlModifier then it works (whereas the second condition changes), but not the key for both () Qt :: Key_F11 In the while I am using windows I press F11.
Edit : checked with logging and the result is that Ctrl + Alt + F11 and Ctrl + Alt + F12 do not send a key event (while others Ctrl + Alt + Fxx keys). Ok, so I managed to solve it, though I am not happy with the solution. There is at least no secret and it works :). I did not get hotkeys Ctrl + Alt + F11 and Ctrl + Alt + F12
Reasons I'm a partner stack of global hotkeys as member mood swords (thanks a lot for this!) Managed to find it using the program of Apparently, the which program has no documented way to detect a particular hotkey (and it has done nothing on my system). See. Solution
One of the responses given in the above thread was forwarded to me. The answer to the ephotinis was right for me. I did not have the experience of setting a lower-level keyboard hook, but it was not as difficult as it seems. For the sake of the future, I have done this in my QT application:
In my main window: Main Menu: Public QMine Window {Q_OBJECT Public: ClearMain Wando (QWidget * Parent = 0); ~ MainWindow (); // ... Code Private: void tryLogin (); Friends LRESULT Callback Low Level Keyboardpresc (Int Code, Varm Uponam, Lapram Liparam); }; LRESULT callback low level keyboardpresc (int code, varm usage, Lapram leoparam); In my mainwindow.cpp:
// Set hook in Constructor SetWindowsHookEx (WH_KEYBOARD_LL, Low Level Keyboard Board, Zero); Hook code (mostly from the north of the Epoitinis): LRESULT callback low level keyboardbreak (int code, varm use, LPARAM liparm) {KBDLLHOOKSTRUCT * kllhs = reinterpret_cast & lt; KBDLLHOOKSTRUCT * & gt; (LParam); If (code == HC_ACTION) {if (wParam == WM_KEYDOWN & amp; kllhs-> vkCode == VK_F12 & amp; (GetAsyncKeyState (VK_MENU) & lt; 0 & amp; amp; ; GetAsyncKeyState (VK_CONTROL) & lt; 0)} {Main Window * W = Dynamic_Cast & lt; Manwando * & gt; (QApp-> ActiveWindow ()); If (null! = W) {w-> tryLogin (); // It should not be blocked! Return 1; }}} Return CallNextHookEx (0, code, wordpress, leiparam); } As you can see, we get the pointer from the global QApplication object in the application window. We use dynamic_cast, so there is no main window example in the active window, we will get a zero point
If you are thinking that GetAsyncKeyState calls for & lt; 0, this is because this function returns with the MSB set if the key is down and when MSB is set, then the smallest number is negative (on x86 / x64 and compatible platforms). If the windows are ever placed on a platform where the signed anteceders are represented separately, this code may be broken. Will have to make a 16-bit mask in the right way and it will be used to look at MSB, but I'm lazy to do this. :)
To note a thing that when you call a function from your hook, the QT event has been started loop bus processing. This means that unless you come back from your function, then this UI will stop (freezing for a few seconds). If you wanted to show I did something like a dialogue instead, then executive () , call increase, activateWindow and show , window When modulating the device (in its manufacturer perhaps) the modal You can unregister the hook with the if you want (which happens when the hook containing module is unloaded). To do this, save the return value of the SetWindowsHookEx call.
Comments
Post a Comment