测试按钮按键事件

今天在工作中,需要检查内存泄漏,所以临时需要关闭应用程序 nicely .
我们设计游戏的Kernel 一般不要关闭它,它是一个不可见的APP,所以在程序的Framemove中加入了下面这个,快速解决了我的问题, 查到了这篇文章

To check if a key was pressed when you process a mouse message,
(GetKeyState(key) & 0x8000) /* for example, key=VK_SHIFT */

This will get the state of the key *when the current message was
generated*. If you need to know whether it is pressed right now, use
GetAsyncKeyState().

If you need instead to check the state of the mouse button(s) when
processing keyboard messages, you can use:
(GetKeyState(VK_LBUTTON) & 0x8000)
(GetKeyState(VK_RBUTTON) & 0x8000)

Note: these will return the state of the *physical* left and right
buttons, which will be reversed if the user has switched them in the
mouse control panel.

I define macros to avoid scattering code with constants, and to get a
1 or 0 result:

#define WAS_PRESSED(key) ((GetKeyState(key) & 0x8000) != 0)
#define IS_PRESSED(Key) ((GetAysncKeyState(key) & 0x8000) != 0)

你可能感兴趣的:(测试按钮按键事件)