Intercept mouse input

2019-05-20 19:01发布

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.

5条回答
时光不老,我们不散
2楼-- · 2019-05-20 19:16

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.

查看更多
不美不萌又怎样
3楼-- · 2019-05-20 19:21

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.

查看更多
狗以群分
4楼-- · 2019-05-20 19:24

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.

查看更多
Explosion°爆炸
5楼-- · 2019-05-20 19:24

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;

    ((WINDOWPOS*)lParam)->flags =  SWP_NOOWNERZORDER | SWP_NOMOVE;
    break;

default:
    break;
}
return ::CallWindowProc(m_nOldWindowProc, hwnd, message, wParam, lParam);

}

查看更多
趁早两清
6楼-- · 2019-05-20 19:26

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

查看更多
登录 后发表回答