使用GetKeyState() [英] Using GetKeyState()

查看:987
本文介绍了使用GetKeyState()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当按下一个键时,我想要一个布尔事件切换。具体来说,'s'键。我已经指向函数GetKeyState(),它应该在Win32 API下工作。我知道字母's'的ASCII代码是115,因此我的代码如下:

I would like to have a boolean event toggle when a key is pressed. Specifically, the 's' key. I have been pointed to the function GetKeyState(), which supposedly works under the Win32 API. I understand the ASCII code for the letter 's' is 115, and so my code is as follows:

if (GetKeyState(115) == 1)
{
<EVENT>
}

但是,这不起作用。为什么?以下是MSDN参考资料: http://msdn.microsoft.com/ en-us / library / ms646301%28v = vs.85%29.aspx ...如果低位是1,键将被切换

However, this does not work. Why? Here is the MSDN reference: http://msdn.microsoft.com/en-us/library/ms646301%28v=vs.85%29.aspx ... "If the low-order bit is 1, the key is toggled"

推荐答案

根据我的理解,您需要:

From what I understand you need to do:

if( GetKeyState(115) & 0x8000 )
{
    <EVENT>
}

最高位指示是否按下键。最低值表示键是否被切换(例如,如果大写锁定已打开)。

The highest bit tells if key is pressed. The lowest tells if key is toggled (like, if caps lock is turned on).

这篇关于使用GetKeyState()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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