获取QKeyEvent的关键位置(多平台) [英] Get key position of QKeyEvent (multiplatform)

查看:137
本文介绍了获取QKeyEvent的关键位置(多平台)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了制作适用于所有键盘布局的基于位置的键盘快捷键,我需要确定一个物理键盘键,而键盘布局不位于其上方.理想情况下,我想检索QKeyEvent的扫描代码,因为它与键盘布局无关.

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.

例如,如果我想将Shift+Q映射到减小音量,并且将Shift+W映射到增大音量(两个键彼此相邻)根据

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.

现在,问题是:如何在所有平台上都可以使用QKeyEvent的扫描代码或任何其他说明物理键位置的参数,而忽略键盘布局呢?我希望它可以在Windows,Linux和OSX上运行.

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()完成任务,但是它不适用于OSX:\

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

推荐答案

您已经拥有最跨平台的方法.至少从Qt 5.7起,Qt尚未在OS X上实现它.

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.

可以随意修补您的Qt副本,使其包含HID事件点击以获取扫描代码,请参见例如这个问题.

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

这篇关于获取QKeyEvent的关键位置(多平台)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆