Get key position of QKeyEvent (multiplatform)

风流意气都作罢 提交于 2019-12-02 08:53:31

问题


In order to make position-based keyboard shortcuts, that work for all keyboard layouts, I need to identify a physical keyboard key, without the keyboard layout on top of it. Ideally, I would like to retrieve the scancode of the QKeyEvent, because that is not keyboard layout-dependent.

For example, if I would want to map Shift+Q to volume-down and Shift+W to volume-up (two keys which are next to each other on a US keyboard layout) I could just map these to Shift+0x10 and Shift+0x11, according to this scancode set. This way, it will also work for French keyboard layouts, where the Q and the A are switched. And it will even work for DVORAK keyboard layouts or other exotical keyboard layouts, because the keyboard layout will be just ignored.

Now, the question is: How can I retrieve QKeyEvent's scancode, or any other parameter telling about the physical key's position, ignoring the keyboard layout, that will work on all platforms? I want it to work on Windows, Linux and OSX.

QKeyEvent::nativeScanCode() gets the job done, but it doesn't work for OSX :\


回答1:


You already have the most multiplatform way of doing it. Except that Qt hasn't implemented it for OS X yet, at least as of Qt 5.7.

Feel free to patch your copy of Qt to include a HID event tap to get the scancodes, see e.g. this question.



来源:https://stackoverflow.com/questions/38377454/get-key-position-of-qkeyevent-multiplatform

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!