Recent

Author Topic: Global Hotkey in QT5 applications  (Read 2468 times)

El Salvador

  • Full Member
  • ***
  • Posts: 134
Global Hotkey in QT5 applications
« on: December 13, 2020, 11:12:35 am »
Hi everybody,

I want porting global hotkey (start an action when a combination of keys is pressed, no form focus required) in QT. In Windows (https://github.com/salvadorbs/Asuite/blob/develop/Library/platform/win32/Hotkeys.Manager.Platform.inc), it is very simple, and in GTK2 (https://github.com/salvadorbs/Asuite/blob/develop/Library/platform/gtk2/Hotkeys.Manager.Platform.inc), i succeeded to use gdk* api (thanks to cross.codebot's code). But in qt5? Maybe I need to use https://doc.qt.io/qt-5/qcoreapplication.html#installNativeEventFilter ?

Thank you very much

zeljko

  • Hero Member
  • *****
  • Posts: 1594
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Global Hotkey in QT5 applications
« Reply #1 on: December 16, 2020, 11:25:34 am »
Yes, I think that only via installNativeEventFilter you can achieve global hotkeys.

El Salvador

  • Full Member
  • ***
  • Posts: 134
Re: Global Hotkey in QT5 applications
« Reply #2 on: December 18, 2020, 04:22:13 pm »
Yes. But unfortunately, it isn't so simple with actual libQT5Pas. So I develop a very simple lib in C to create a QAbstractNativeEventFilter class, hook it with QCoreApplication and pass every event XCB_KEY_PRESS (with param KeyCode and KeyState) to Pascal.

The result? https://github.com/salvadorbs/AsuiteComps/tree/main/library - Now we can register global hotkey in Windows and Linux (GTK2 and QT5).

zeljko

  • Hero Member
  • *****
  • Posts: 1594
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Global Hotkey in QT5 applications
« Reply #3 on: December 23, 2020, 09:54:10 am »
That looks great. Maybe I can update libQt5Pas for next major lazarus version so no need for extra c library. You code can be added to qt5 interface (with your permission of course), but in that case it can be splitted for gtk2,gtk3,qt and qt5 interfaces. Or create package for hotkeys and use it on demand.

El Salvador

  • Full Member
  • ***
  • Posts: 134
Re: Global Hotkey in QT5 applications
« Reply #4 on: December 30, 2020, 09:51:55 am »
It would be great. Of course, you can use my code!

 

TinyPortal © 2005-2018