GetKeyState()vs.GetAsyncKeyState()vs.getch()? [英] GetKeyState() vs. GetAsyncKeyState() vs. getch()?

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

问题描述

通过以下方式获得按键之间有什么区别?

What's the difference between getting a key press with:

  • GetKeyState()
  • GetAsyncKeyState()
  • getch()?
  • GetKeyState()
  • GetAsyncKeyState()
  • getch()?

我什么时候应该使用另一个?

When should I use one over the other?

推荐答案

GetKeyState()和GetAsyncKeyState()是Windows特定的API,而getch()可在其他非Windows特定的C编译器上使用.

GetKeyState() and GetAsyncKeyState() are Windows specific APIs, while getch() works on other non-Windows-specific C compilers.

GetKeyState()获取从线程的消息队列中返回的键状态.该状态不反映与硬件相关联的中断级别状态.

GetKeyState() gets the key status returned from the thread's message queue. The status does not reflect the interrupt-level state associated with the hardware.

GetAsyncKeyState()指定自上次调用GetAsyncKeyState()以来是否按下了该键,以及该键当前是向上还是向下.如果设置了最高有效位,则该键处于按下状态;如果设置了最低有效位,则在上一次调用GetAsyncKeyState()之后按下了该键.

GetAsyncKeyState() specifies whether the key was pressed since the last call to GetAsyncKeyState(), and whether the key is currently up or down. If the most significant bit is set, the key is down, and if the least significant bit is set, the key was pressed after the previous call to GetAsyncKeyState().

我在实践中看到的是,如果按住某个键并在按下该键时分配一个行为,那么如果使用GetKeyState(),则该行为的调用次数将比使用GetAsyncKeyState的次数多. ().

What I've seen in practice is that if you hold a key pressed and assign a behavior when the key is pressed, if you use GetKeyState(), the behavior will be called more times than if you'd have used GetAsyncKeyState().

在游戏中,我更喜欢使用GetAsyncKeyState().

In games, I prefer using GetAsyncKeyState().

(您也可以在MSDN博客上查看更多详细信息).

(You can also check for more details on the MSDN blog).

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

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