Run the code in a debugger, and press the keys as the following sequence: press A-> press B -> release A -> release B.
The expected console output would be:
A pressed
B pressed
A released
B released
But the actual output is:
A pressed
B pressed
B released
Where A released is missing. Further more, when pressing multiple hotkeys at the same time, only the last hotkey would emit the released signal.
Cause of the bug
The QHotkeyPrivateWin class only polls the release of the last hotkey being pressed, and the previous hotkeys are replaced by the new pressed hotkey. The link to the related code is here.
Use a container like QList<QHotkey::NativeShortcut> to maintain all the keys being pressed but not yet released, and use std::remove_if to emit the released signal and remove the corresponding NativeShortcut from the container.
Steps to reproduce
I'm using Qt6.4.3 on windows 11. Here is a minimum demo code for reproducing the bug:
Run the code in a debugger, and press the keys as the following sequence:
press A-> press B -> release A -> release B
.The expected console output would be:
But the actual output is:
Where
A released
is missing. Further more, when pressing multiple hotkeys at the same time, only the last hotkey would emit thereleased
signal.Cause of the bug
The
QHotkeyPrivateWin
class only polls the release of the last hotkey being pressed, and the previous hotkeys are replaced by the new pressed hotkey. The link to the related code is here.Possible solution
Use a container like
QList<QHotkey::NativeShortcut>
to maintain all the keys being pressed but not yet released, and usestd::remove_if
to emit thereleased
signal and remove the correspondingNativeShortcut
from the container.