Skycoder42 / QHotkey

A global shortcut/hotkey for Desktop Qt-Applications
BSD 3-Clause "New" or "Revised" License
552 stars 162 forks source link

Odd implementation question. #42

Closed cpyarger closed 3 years ago

cpyarger commented 4 years ago

Hi, I am looking to register multiple hotkeys to a single callback. But pass through the qkeysequence and bool pressed to that callback. How would I go about setting that up?

Skycoder42 commented 4 years ago

QHotkey is a standart Qt class with signals and slots. Thus, you can get the sender of a signal via QObject::sender.

basic example (pseudocode)

auto hotkey1 = new QHotkey(...);
auto hotkey2 = new QHotkey(...);
auto hotkey3 = new QHotkey(...);

connect(hotkey1, &QHotkey::activated, this, &MyClass::myCallback);
connect(hotkey2, &QHotkey::activated, this, &MyClass::myCallback);
connect(hotkey3, &QHotkey::activated, this, &MyClass::myCallback);

void MyClass::myCallback() {
    auto hotkey = qobject_cast<QHotkey>(QObject::sender());
    qDebug() << hotkey.shortcut();
}
cpyarger commented 4 years ago

Thank you! I stumbled across this a few days back and got it working! Any chance you would be willing to help out with doing the same thing you did here with midi? I have been poking the rtmidi17 library and would to see it have a QT5 implementation