c ++ global WM_KEYDOWN? [英] c++ global WM_KEYDOWN?
问题描述
你好。
我正在练习c ++而我正在尝试建立一个按键计数项目(我想计算用户每天按下的键数。
I'm practicing at c++ and i'm trying to build a project for key pressed count (i want to count the keys that user press per day).
所以我使用的是Microsoft visual studio,我创建了一个win32项目(桌面应用程序)。
So i'm using Microsoft visual studio, and i create a win32 project (desktop application).
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){
 切换(消息)   {
switch (message) {
案例WM_KEYDOWN:
case WM_KEYDOWN:
默认情况下前两行是我添加WM_KEYDOWN。
The first 2 lines was by default and i add the WM_KEYDOWN.
当我按下一个键时它工作得非常好但是当程序最小化时它不起作用。
It works very well when i press a key but its not working when the program is minimized.
所以我想知道有什么方法使它最小化?
So i was wondering there is any way to make it work while is minimized?
推荐答案
窗口程序(WndProc) )当您的桌面应用程序的相关窗口具有键盘焦点时,它只会收到WM_KEYDOWN消息。 当您的应用程序最小化时,它不再具有键盘焦点。
The window procedure (WndProc) of your desktop application will only receive a WM_KEYDOWN message when its related window has the keyboard focus. When your application is minimized it no longer has the keyboard focus.
为了更好地理解Windows如何处理键盘输入,我建议您阅读
https://docs.microsoft.com/en-us/windows/desktop/inputdev/about -keyboard-input
To get a better understanding of how Windows handles keyboard input I suggest you read https://docs.microsoft.com/en-us/windows/desktop/inputdev/about-keyboard-input
因此,您需要做一些不同的事情,以便在其他应用程序收到键盘输入时收到通知。
So you need to do something different in order to be notified when a different application has received keyboard input.
Windows Hooks可以帮助您实现目标。 我建议你阅读
https://docs.microsoft.com/en- us / windows / desktop / winmsg / about-hooks
Windows Hooks can help you achieve your objective. I suggest you read https://docs.microsoft.com/en-us/windows/desktop/winmsg/about-hooks
可以在
https://docs.microsoft.com/en-us/windows/desktop/winmsg/using-hooks
接收按键信息的另一个选择是使用原始输入。 请参阅
https://docs.microsoft.com/en-us/windows / desktop / inputdev / raw-input
Another option to receive keypress information is to use raw input. See https://docs.microsoft.com/en-us/windows/desktop/inputdev/raw-input
这篇关于c ++ global WM_KEYDOWN?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!