拦截鼠标输入
我想知道是否有办法在鼠标输入到达窗口之前拦截并修改它?
我想要做的是拦截鼠标运动事件,对值应用一些自定义缩放和加速,然后继续传递它们。我需要一些东西可以在输入到达原始输入 API 或 DirectInput 之前执行此操作。
I was wondering if there is a way to intercept and modify mouse input before it gets to windows?
What I'm wanting to do is intercept mouse motion events, apply some custom scaling and acceleration to the values, and then continue passing them along. I'd need something that can do this before the inputs get to the raw input API or DirectInput.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
为了影响登录期间的所有鼠标输入(包括 DirectInput 和 SAS 屏幕等),您需要将筛选器驱动程序加载到鼠标驱动程序堆栈中。
其他人已经做到了,例如 http://www.maf-soft.de/mafmouse/
Windows DDK 中应该有一个
moufiltr
示例,您可以将其用作起点。您很可能希望使用虚拟机进行开发,因为开发计算机上的驱动程序中的错误可能很难恢复。In order to affect all mouse input, including DirectInput, during logon and the SAS screen, etc., you'll need to load a filter driver into the mouse driver stack.
Other people have done it, for example http://www.maf-soft.de/mafmouse/
There should be a
moufiltr
sample in the Windows DDK which you can use as a starting point. You will most likely want to use a virtual machine for development since errors in a driver on your development machine could be difficult to recover from.你见过这种无需制作过滤驱动程序或钩子就能拦截鼠标和键盘输入的方法吗?
http://oblita.com/Interception.html
Have you seen this method of intercepting mouse and keyboard input without having to make a filter driver or hook?
http://oblita.com/Interception.html
您可以使用
LowLevelMouseProc
挂钩过程可以用来获取有关进入系统的任何鼠标输入的信息,尽管我怀疑您是否真的可以更改此信息(并且文档对此保持沉默)。如果失败,
GetMsgProc
是替代方法它允许您拦截发布到任何窗口的所有消息。虽然这个钩子确实允许您修改消息,但可能已经太晚了,无法对 DirectInput 等 API 产生任何影响。There is a
LowLevelMouseProc
hook procedure that you can use to get information on any mouse input entering the system, although I doubt if you can actually change this information (and the docs are silent on this).If this fails,
GetMsgProc
is an alternative that lets you intercept all messages posted to any window. Though this hook does let you modify the message, it's probably too late to have any effect on APIs such as DirectInput.您可以尝试 windows 挂钩 - 这是您设置为在 Windows 消息传递到系统其余部分之前接收它们的函数 - a CBT hook(用于基于计算机的培训)可能会为您带来最佳效果。
我不知道这是否适用于 DirectInput 或 MS 添加的其他新东西,以打破所有旧的内部一致性。不过设置起来很容易,所以尝试一下看看。
You could try a windows hook - which are functions you set to receive windows messages before they get passed through to the rest of the system - a CBT hook (for computer based training) is what might get you best results.
I don't know Whether this will work with DirectInput or the other new stuff MS has added to break all the old internal consistency. Its easy to set up though, so try it and see.
据我所知,最好的方法是挂钩Windows消息循环,在你的情况下,你应该传递HWND 0(如果我没记错的话,这是桌面的HWND),这样所有消息都会首先通过你的函数。
http://msdn.microsoft.com/en-us /library/ms633591%28VS.85%29.aspx
有关挂钩的更多信息:http://msdn.microsoft.com/en-us/library/ms644959%28VS.85%29.aspx
使用方式如下:
m_nOldWindowProc = ::SetWindowLong(0 /我认为.../, GWL_WNDPROC, (LPARAM)(WNDPROC)WindowProcCallback);
和回调:
LRESULT CALLBACK CStubWindow::WindowProcCallback(HWND hwnd,
UINT 消息、WPARAM wParam、LPARAM lParam)
{
开关(消息)
{
案例 WM_WINDOWPOSCHANGING:
((WINDOWPOS*)lParam)->cx = STATUS_BAR_WIDTH;
}
As far as I know the best way is to hook to windows message loop, In your case you should pass HWND 0 (If I remember correctly this the HWND of the desktop) so all the messages will pass though your function first.
http://msdn.microsoft.com/en-us/library/ms633591%28VS.85%29.aspx
More on hooks : http://msdn.microsoft.com/en-us/library/ms644959%28VS.85%29.aspx
Use it as follows:
m_nOldWindowProc = ::SetWindowLong(0 /I think.../, GWL_WNDPROC, (LPARAM)(WNDPROC)WindowProcCallback);
and the callback:
LRESULT CALLBACK CStubWindow::WindowProcCallback(HWND hwnd,
UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_WINDOWPOSCHANGING:
((WINDOWPOS*)lParam)->cx = STATUS_BAR_WIDTH;
}