【发布时间】:2011-09-13 23:35:35
【问题描述】:
我希望在按下某个键时切换一个布尔事件。具体来说,“s”键。我被指出了函数 GetKeyState(),它应该在 Win32 API 下工作。我知道字母 's' 的 ASCII 码是 115,所以我的代码如下:
if (GetKeyState(115) == 1)
{
<EVENT>
}
但是,这不起作用。为什么?这里是 MSDN 参考:http://msdn.microsoft.com/en-us/library/ms646301%28v=vs.85%29.aspx ...“如果低位为 1,则键被切换”
【问题讨论】:
-
只需将其与零进行比较 -> 请参阅:How do I get the high- and low-order bits of a SHORT?