Skycoder42 / QHotkey

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

Can't register shortcut on windows #15

Closed Shatur closed 6 years ago

Shatur commented 6 years ago

I used this code from readme:

QHotkey hotkey(QKeySequence("ctrl+alt+Q"), true);//The hotkey will be automatically registered
            qDebug() << "Is Registered: " << hotkey.isRegistered();

            QObject::connect(&hotkey, &QHotkey::activated, qApp, [&](){
                qDebug() << "Hotkey Activated - the application will quit now";
                qApp->quit();
            });

And got the following:

QHotkey: Unable to map shortcut to native keys. Key: Qt::Key(Key_Q) Modifiers: QFlags<Qt::KeyboardModifiers>(ControlModifier|AltModifier)
Is Registered:  false

Any other key sequence don't work too.

I also tried HotkeyTest and got this errors on start:

QHotkey: Unable to map shortcut to native keys. Key: Qt::Key(Key_F) Modifiers: QFlags<Qt::KeyboardModifiers>(NoModifier)
QHotkey: Unable to map shortcut to native keys. Key: Qt::Key(Key_K) Modifiers: QFlags<Qt::KeyboardModifiers>(ShiftModifier|AltModifier)
QHotkey: Unable to map shortcut to native keys. Key: Qt::Key(Key_K) Modifiers: QFlags<Qt::KeyboardModifiers>(ShiftModifier|AltModifier)

But when I assign key sequence in app menu - it works. Is this bug or I doing something wrong?

Windows 10 x64 Qt 5.10 MinGW 5.3.0 32bit

P.S. On ArchLinux the same code works properly.

Skycoder42 commented 6 years ago

I tried it on a Windows Machine with the exact same setup as yours, and I can register shortcuts as expected. Maybe something is broken on your system or in your application.

Please try compiling and running the HotkeyTest project and check if that works.

Shatur commented 6 years ago

Hmm ... It's weird, but I just now tested my code and "HotkeyTest" on another Windows machine with the same setup and everything works. I think that something has broken in my system. Excuse for troubling!

semanser commented 6 years ago

@Shatur95 I have faced with the same issue on another windows machine. The root of the problem is the same as in #17. Try to update the lib to the latest version and everything should work ok.

Shatur commented 6 years ago

@semanser, thank you, I'll test it soon :)

semanser commented 6 years ago

@Shatur95 update: on qpm this package is still didn't updated, so if you want to try it just clone from the github but not from qpm.

Shatur commented 6 years ago

@semanser, yes, I always use GitHub version!

Shatur commented 6 years ago

@semanser, thanks, your commit helped :)