Bugs with keyboard handling in dialog boxes


There are in general a few issues with keyboard events. Checkout develop and modify the HelloWorld example as follows:

MainComponent.h (2.4 KB)
MainComponent.cpp (6.8 KB)
Main.cpp (3.9 KB)

Now we can observe 2 bugs:

  • After starting you can’t interact with the window using the keyboard. You have to click on the window first. The same occurs after you minimize using the minimize button and restore using the taskbar. The only exception are button shortcuts.

  • The OK button has returnKey as its shortcut (which is a common setup in dialog boxes). Now bring the keyboard focus to the toggle button, and press return:

    • Normally the return key will trigger a button click on a button (so the toggle button will change state).
    • But observe how both the toggle button will change state, and the OK button click will be triggered.

The button shortcuts are an example of events handled using the keyStateChanged callback. This can be quite surprising, since it allows parent components to handle events which are filtered out in the keyPressed callback (by returning false). And since keyStateChanged doesn’t receive the changed key, it’s hard to filter out events there.

Any thoughts on how to handle this problem?