在WM_KEYDOWN消息中获取lParam参数的第30位 [英] Get 30th bit of the lParam param in WM_KEYDOWN message
问题描述
我需要获取通过WM_KEYDOWN消息传递的lParam参数的第30位。此位写入此处允许我知道键是否被按下。这个代码是否正确?
(lParam>> 30)& 1
lParam& 0x40000000 。如果这不是零,那么设置 b30
(我认为三十二的三十个位,顺便说一句)。更有可能是 {logical-and,compare}
操作,而不是 {shift,logical-and,compare} $请注意,即使你使用了
(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
I would just use lParam & 0x40000000
. If that's non-zero, then b30
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?
这篇关于在WM_KEYDOWN消息中获取lParam参数的第30位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!