我可以将原始鼠标输入作为 WM_INPUT 两次吗?
我正在尝试通过在其主线程之外添加输入收集线程来修改现有应用程序。
原始应用程序已经在其主循环内处理了鼠标输入,但它以我项目正确工作的速度非常慢。
因此,我想以很高的速率处理主线程外部的鼠标输入,而不会干扰原始应用程序的输入处理过程?我该怎么做?我可以注册鼠标设备并获取相应的WM_INPUT,而无需阻止原始应用程序执行自己的处理?
I am trying to modify an existing application by adding an input gathering thread outside of its main thread.
The original application already processes mouse input pretty decently inside its main loop, but it does so at a rate that's very slow for my project to properly work.
So I want to process mouse input outside the main thread on a very high rate, without interfering with the original application's input handling process at all? How can I do that? Can I register a mouse device and get corresponding WM_INPUT without preventing the original app from doing its own processing untouched?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在单独的线程中注册原始输入。但首先您需要在该线程中创建不可见窗口。另外,要在该线程中接收输入,您需要向
RegisterRawInputDevices()
调用提供RIDEV_INPUTSINK
。这是我的代码:
你甚至可以使WM_CHAR 通过从
WM_INPUT
键盘消息发布WM_KEYDOWN
来在您的线程中工作:另一种更常见的方法是推送队列中的 WM_INPUT 事件(可能是无锁的)并在某些输入工作线程中处理它们,该线程可以向程序的其他部分发出输入事件等。
You can register for Raw Input in a separate thread. But first you need to create invisible window in that thread. Also to receive input in that thread you need to provide
RIDEV_INPUTSINK
to yourRegisterRawInputDevices()
call.Here is my code that doing that:
You even can make WM_CHAR to work in your thread by posting
WM_KEYDOWN
fromWM_INPUT
keyboard messages:Another more common approach is to push
WM_INPUT
events in queue (possibly lockless) and process them in some input worker thread that could emit input events etc to other parts of your program.