将 CHotKeyCtrl 中的热键从虚拟代码转换为字符串并向后转换
我有 CHotKeyCtrl
,我可以从中获取虚拟键代码和修饰符。我还可以调用 CHotKeyCtrl::GetHotKeyName 来获取此热键的字符串视图 - 我可以向用户显示此字符串并将其存储在我的 XML 配置文件中。但是如何将该字符串向后转换为虚拟键代码和修饰符呢?我不想在 XML 中仅保存 WORD
形式的虚拟键码和中间符(它的信息量不是很大)。
I have CHotKeyCtrl
and I can get virtual Key Code and modifiers from it. I also can call CHotKeyCtrl::GetHotKeyName
to get string view of this hotkey - I can show this string to user and store it in my XML config file. But how to convert this string backward to virtual key code and modifiers? I do not want to save in XML just virtual keycode and midifiers in WORD
form (it's not very informative).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知,不支持将热键名称转换为虚拟键代码+修饰符对,主要是因为 GetHotKeyName() 返回一个本地化名称。该名称来自键盘驱动程序,并且会因 Windows 安装的不同而有所不同。
由于 WM_SETHOTKEY 采用虚拟键代码及其修饰符,打包到 < code>WPARAM,您可以构建该值并将其存储在 XML 设置中,以避免使用两个元素/属性。您还可以包含热键名称以便于阅读,但仅存储该名称不会为您提供随后发送
WM_SETHOTKEY
所需的信息。To my knowledge, there is no support out of the box to convert a hot key name into a virtual key code + modifiers pair, mainly because GetHotKeyName() returns a localized name. That name comes from the keyboard driver and will vary from one Windows installation to the other.
Since WM_SETHOTKEY takes a virtual key code and its modifiers, packed into a
WPARAM
, you can build that value and store it in your XML settings in order to avoid using two elements / attributes. You can also include the hot key name for easier reading, but storing only that name will not give you the information required to sendWM_SETHOTKEY
afterwards.