获取WM_KEYDOWN消息中lParam参数的第30位
我需要获取随 WM_KEYDOWN 消息传递的 lParam 参数的第 30 位。 此处所写的这一点允许我知道之前是否按下过该键。这段代码正确获取吗?
(lParam >> 30) & 1
I need to get the 30th bit of the lParam param passed with the WM_KEYDOWN message. This bit as written here allows me to know if the key was pressed before. Is this code right to get it?
(lParam >> 30) & 1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我只会使用 lParam & 0x40000000。如果该值非零,则设置了
b30
(顺便说一句,我认为是三十二位的第 30 位)。而且更有可能它是一个{逻辑与,比较}
操作,而不是{shift,逻辑与,比较}
。请注意,即使您使用
(lParam >> 30) & ,一个像样的编译器也很有可能生成更有效的代码。 1
但为什么要冒这个险呢?I would just use
lParam & 0x40000000
. If that's non-zero, thenb30
was set (I consider that the thirty first bit of the thirty two, by the way). And there's more likelihood that it will be a{logical-and, compare}
operation rather than{shift, logical-and, compare}
.Mind you, there's a good chance that a decent compiler would generate the more efficient code anyway even if you used
(lParam >> 30) & 1
but why take the risk?