[C++] How to change the mouse position in Mouse Hook
-
Dear All, This is my first time to ask question on this platform. The question is: I want to write a program, which can modify the mouse position to achieve inverting mouse movement, like wanna move up but it goes down. wanna move left but it goes right. here is the callback sample code, but I can get what I want. What can I do?
LRESULT CALLBACK MouseHookProc2(int nCode, WPARAM wParam, LPARAM lParam)
{if(wParam == WM\_MOUSEMOVE ||wParam == WM\_NCMOUSEMOVE) { MOUSEHOOKSTRUCT\* data=(MOUSEHOOKSTRUCT\*) lParam; LPARAM lParam2= MAKELPARAM(0,data->pt.y); return CallNextHookEx(NULL,nCode,wParam,lParam2); }
return CallNextHookEx(NULL,nCode,wParam,lParam);
} -
Dear All, This is my first time to ask question on this platform. The question is: I want to write a program, which can modify the mouse position to achieve inverting mouse movement, like wanna move up but it goes down. wanna move left but it goes right. here is the callback sample code, but I can get what I want. What can I do?
LRESULT CALLBACK MouseHookProc2(int nCode, WPARAM wParam, LPARAM lParam)
{if(wParam == WM\_MOUSEMOVE ||wParam == WM\_NCMOUSEMOVE) { MOUSEHOOKSTRUCT\* data=(MOUSEHOOKSTRUCT\*) lParam; LPARAM lParam2= MAKELPARAM(0,data->pt.y); return CallNextHookEx(NULL,nCode,wParam,lParam2); }
return CallNextHookEx(NULL,nCode,wParam,lParam);
}I think you are approaching the problem from a wrong direction. The mouse works the following way: The hardware sends movement deltas to the machine and to the OS via the driver and there it gets accumulated into a mouse position value. If you want to invert the movement you have to invert the deltas because you simply can't do that with the position. Maybe if you knew the previous value of the position... But even in that case that would be quite a messy solution. Another problem with this solution is that as far as I know most hook types are not allowed to modify the incoming parameters and they have to pass on them to the next hook handler unmodified. You should probably write a mouse filter driver: http://code.msdn.microsoft.com/windowshardware/Moufiltr-WDF-Version-fb57f5de[^] http://www.maf-soft.de/mafmouse/[^]
-
I think you are approaching the problem from a wrong direction. The mouse works the following way: The hardware sends movement deltas to the machine and to the OS via the driver and there it gets accumulated into a mouse position value. If you want to invert the movement you have to invert the deltas because you simply can't do that with the position. Maybe if you knew the previous value of the position... But even in that case that would be quite a messy solution. Another problem with this solution is that as far as I know most hook types are not allowed to modify the incoming parameters and they have to pass on them to the next hook handler unmodified. You should probably write a mouse filter driver: http://code.msdn.microsoft.com/windowshardware/Moufiltr-WDF-Version-fb57f5de[^] http://www.maf-soft.de/mafmouse/[^]
-
Thanks for your information lead me to the right direction. I will study driver filter then. thanks
You are welcome! Good luck, have fun!
-
Dear All, This is my first time to ask question on this platform. The question is: I want to write a program, which can modify the mouse position to achieve inverting mouse movement, like wanna move up but it goes down. wanna move left but it goes right. here is the callback sample code, but I can get what I want. What can I do?
LRESULT CALLBACK MouseHookProc2(int nCode, WPARAM wParam, LPARAM lParam)
{if(wParam == WM\_MOUSEMOVE ||wParam == WM\_NCMOUSEMOVE) { MOUSEHOOKSTRUCT\* data=(MOUSEHOOKSTRUCT\*) lParam; LPARAM lParam2= MAKELPARAM(0,data->pt.y); return CallNextHookEx(NULL,nCode,wParam,lParam2); }
return CallNextHookEx(NULL,nCode,wParam,lParam);
}Give calling SetCursorPos[/\] a try.
Steve
-
Give calling SetCursorPos[/\] a try.
Steve
-
You are welcome! Good luck, have fun!
-
Dear Bro, Do you know "sakasamouse"? That tool can do excatly what I want. And it seems it is not a driver. because it is an .exe file and has an .dll with it. Do you know how it do? Thanks in advance
No, I don't know it. I use my mouse as it comes with my windows.
-
No, I don't know it. I use my mouse as it comes with my windows.