使用RAWINPUT区分左移键和右移键 [英] Distinguish between left and right shift keys using RAWINPUT

查看:78
本文介绍了使用RAWINPUT区分左移键和右移键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

RAWINPUT提供两个标志(RI_KEY_E0RI_KEY_E1)以检查是否按下了左键或右键.这对于CTRL很有用,但不适用于左右移位.实际上,两者的标志都相同,并且VKey也相同(VK_SHIFT).我如何找出按下了哪个档?我正在Windows 7上工作.有趣的是,无论我按哪个shift键,标志/vkey的值都完全相同.

RAWINPUT provides two flags (RI_KEY_E0 and RI_KEY_E1) to check whether the left or right version of a key is pressed. This works great for CTRL, but not for left and right shift. In fact, the flags are the same for both, and the VKey is also the same (VK_SHIFT). How can I find out which shift was pressed? I'm working on Windows 7. Interestingly, the flags/vkey values are exactly the same no matter which shift key I'm pressing.

推荐答案

Windows 7,我只得到VK_SHIFT,从没有L/R变体

Windows 7, and I only get VK_SHIFT, never the L/R variants

这是为什么不能按您认为的方式工作的解释的一部分.这背后有古老的历史.键盘控制器已针对IBM AT重新设计,再次针对增强型键盘进行了重新设计.它开始为添加到键盘布局的键发送0xe0和0xe1前缀.就像右边的Ctrl和Alt键一样.

Which is part of the explanation why this doesn't work the way you think it should do. There's ancient history behind this. The keyboard controller was redesigned for the IBM AT, again for the Enhanced keyboard. It started sending out 0xe0 and 0xe1 prefixes for keys that were added to the keyboard layout. Like the right Ctrl and Alt keys.

但是键盘始终都有两个Shift键.原始的IBM PC并不认为它们是特殊键,它们只是具有不同的扫描代码.在以后的更新中对此进行了维护.因此,您不会获得RI_KEY_E0或E1标志.您必须通过RAWKEYBOARD.MakeCode值来区分它们.左Shift键的编排代码为0x2a,右键为0x36.

But keyboards always had two shift keys. The original IBM PC didn't consider them special keys, they simply have a different scan code. Which was maintained in later updates. Accordingly, you don't get the RI_KEY_E0 or E1 flags for them. You have to distinguish them by the RAWKEYBOARD.MakeCode value. The left shift key has makecode 0x2a, the right key is 0x36.

请注意,左Ctrl和Alt键也没有标志.它们与旧PC键盘布局上的相应键匹配. MSDN库文章中的标志说明不是很准确.

Note that the left Ctrl and Alt keys don't have the flags either. They match the corresponding keys on the old PC keyboard layout. The description of the flags in the MSDN Library article is not very accurate.

这篇关于使用RAWINPUT区分左移键和右移键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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