本文介绍了捕获“全局热键"; (视窗)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在,我一直在尝试创建与一键通"语音聊天应用程序类似的功能,但是到目前为止,我还没有找到合适的解决方案.我没有使用MFC或CLR.

Now I've been trying to create a similar functionality as there is in Push-To-Talk voice chat applications, but so far I couldn't find any fitting solutions to this. I am not using MFC or CLR.

问题很简单.我的窗口通常应该没有聚焦(即最小化等),但是我需要对按键做出反应(基本上,我什至不希望知道按钮是否被按下).不幸的是,WM_KEYDOWN仅在窗口具有键盘焦点时才起作用.我确实知道,例如Teamspeak为此使用DirectInput,但我也知道,没有它也可以完成,这是我非常希望的.

The problem is quite simple. My window should be usually out of focus (ie minimized etc), but I need to react to keypresses (basically, I don't even want to know if the button is being held down or not). Unfortunately, WM_KEYDOWN only works if the window has keyboard focus. I do know that for example Teamspeak uses DirectInput for this, but I'm also aware that it can definitely be done without it as well, which I'd highly prefer.

我可以使用的唯一其他解决方案是使用GetAsyncKeyState进行轮询,但是看起来这也不是一个好的解决方案.如果可能的话,我还是希望使用Windows消息.

The only other solution that I could make work is polling with GetAsyncKeyState, but it looks like this is far from being a good solution either. If at all possible, I'd still prefer using Windows messages.

推荐答案

可以使用 RegisterHotKey 或带有全局低级键盘挂钩.

RegisterHotKey(Cody Gray在建议中建议)可能是这里更合适的选择.

RegisterHotKey (which Cody Gray suggested in the commends) is probably the more suitable choice here.

这篇关于捕获“全局热键"; (视窗)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 01:56