是否可以吞下原始输入中的键? [英] Is it possible to swallow a key in Raw Input?

查看:66
本文介绍了是否可以吞下原始输入中的键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用

I am using the Raw Input API because I need to be able to respond to keys from different USB HID devices differently, even if it is the same key.

我的窗口正确接收到WM_INPUT消息.我可以检索 RAWKEYBOARD结构来获取我需要的所有信息.

My window receives the WM_INPUT messages correctly. I can retrieve the RAWKEYBOARD structure to obtain all the information I need.

现在,我要阻止这些USB设备切换NumLock.我希望Raw Input API可以让我吞下NumLock按键吗?

Now I want to prevent those USB devices from being able to toggle NumLock. I am hoping that the Raw Input API might allow me to swallow the NumLock keypress?

我尝试将WM_INPUT消息的结果设置为1,但这似乎没有效果.

I’ve tried setting the WM_INPUT message’s Result to 1, but that doesn’t seem to have an effect.

(我正在用C#编写代码,但是由于这都是低级Windows API,因此您可能不需要C#或.NET知识就可以回答这个问题.)

(I am writing this in C#, but since this is all low-level Windows API, you probably don’t need knowledge of C# or .NET to answer this.)

是的,我也尝试过使用全局键盘挂钩(SetWindowsHookEx)吞下NumLock按键.不幸的是,当我初始化Raw Input API时,在窗口处于活动状态时不再调用全局键盘钩子.我还尝试在原始输入"之后的 后面设置全局钩子,但效果相同.

Oh yeah, I’ve also tried using a global keyboard hook (SetWindowsHookEx) to swallow the NumLock keypress. Unfortunately, as soon as I initialize the Raw Input API, the global keyboard hook is no longer called while the window is active. I’ve also tried setting the global hook after the Raw Input one, but same effect.

推荐答案

原始输入API不支持吞咽按键.

The Raw Input API does not support swallowing of keypresses.

此外,它不会在同一过程中与SetWindowsHookEx 进行交互.原始输入API初始化后,该钩子便被解除钩住.

Furthermore, it does not interact with SetWindowsHookEx within the same process. As soon as the Raw Input API is initialized, the hook is unhooked.

解决方案是让它们处于单独的进程中.一个过程可以使用SetWindowsHookEx吞下不需要的键,而另一个过程则使用Raw Input API处理经过的按键.然后,您只需运行两个.这对我来说很好.

The solution is to have them in separate processes. One process can use SetWindowsHookEx to swallow the unwanted keys, while another uses the Raw Input API to process the keypresses that do come through. Then you just run both. This worked just fine for me.

这篇关于是否可以吞下原始输入中的键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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