completely restrict mouse movement (including raw data)
-
Hi, I want to confine mouse movement. Let's say I want to confine mouse movement to x-direction (so only horizontal movement is possible) when pressing a certain button. This should work globally. What I mean with that is, that I want to use this in any windows program. Let's take MS Paint as an example: When my program runs and I press the certain button, the movement of the mouse should be restricted to horizontal movement. So when drawing a straight horizontal line should be the result. My research so far led me to ClipCursor, but ClipCursor seems to only affect the mousecursor, not the raw data. So returning to the example of MS Paint the following happens: The cursor moves on the horizontal line, but the mouse data received by paint is different: So if you move the mouse slightly in y-direction this still affects the line drawn, also the mouse cursor itself does not indicate that (stays on the straight line). So the result is not a straight line as expected. Does anybody know how to solve that problem ? (as ClipCursor does not confine the raw data sent to an application, it seems to be the wrong routine for doing that) Thanks in advance.
-
Hi, I want to confine mouse movement. Let's say I want to confine mouse movement to x-direction (so only horizontal movement is possible) when pressing a certain button. This should work globally. What I mean with that is, that I want to use this in any windows program. Let's take MS Paint as an example: When my program runs and I press the certain button, the movement of the mouse should be restricted to horizontal movement. So when drawing a straight horizontal line should be the result. My research so far led me to ClipCursor, but ClipCursor seems to only affect the mousecursor, not the raw data. So returning to the example of MS Paint the following happens: The cursor moves on the horizontal line, but the mouse data received by paint is different: So if you move the mouse slightly in y-direction this still affects the line drawn, also the mouse cursor itself does not indicate that (stays on the straight line). So the result is not a straight line as expected. Does anybody know how to solve that problem ? (as ClipCursor does not confine the raw data sent to an application, it seems to be the wrong routine for doing that) Thanks in advance.
HHOOK WINAPI SetWindowsHookEx(
__in int idHook,
__in HOOKPROC lpfn,
__in HINSTANCE hMod,
__in DWORD dwThreadId
);http://msdn.microsoft.com/en-us/library/ms644990(VS.85).aspx[^] and then look at: WH_MOUSE or WH_MOUSE_LL to get what you need. WH_MOUSE_LL gives a little bit more information, but may not be needed in your application.
-
Hi, I want to confine mouse movement. Let's say I want to confine mouse movement to x-direction (so only horizontal movement is possible) when pressing a certain button. This should work globally. What I mean with that is, that I want to use this in any windows program. Let's take MS Paint as an example: When my program runs and I press the certain button, the movement of the mouse should be restricted to horizontal movement. So when drawing a straight horizontal line should be the result. My research so far led me to ClipCursor, but ClipCursor seems to only affect the mousecursor, not the raw data. So returning to the example of MS Paint the following happens: The cursor moves on the horizontal line, but the mouse data received by paint is different: So if you move the mouse slightly in y-direction this still affects the line drawn, also the mouse cursor itself does not indicate that (stays on the straight line). So the result is not a straight line as expected. Does anybody know how to solve that problem ? (as ClipCursor does not confine the raw data sent to an application, it seems to be the wrong routine for doing that) Thanks in advance.
Additionally to what elchupathingy said, you might also try to globally hook[^] GetCursorPos[^].
> The problem with computers is that they do what you tell them to do and not what you want them to do. < > "It doesn't work, fix it" does not qualify as a bug report. < > Amazing what new features none of the programmers working on the project ever heard of you can learn about when reading what the marketing guys wrote about it. <
-
Additionally to what elchupathingy said, you might also try to globally hook[^] GetCursorPos[^].
> The problem with computers is that they do what you tell them to do and not what you want them to do. < > "It doesn't work, fix it" does not qualify as a bug report. < > Amazing what new features none of the programmers working on the project ever heard of you can learn about when reading what the marketing guys wrote about it. <
Selectively injecting a DLL and hooking the functions you need is IMO the better solution. More complicated than using SetWindowHookEx, but will not have the overhead and annoying problems that are associated with global hooks...IE getting the mouse stuck on your horizontal plane, which I think is not what is to happen.
-
Selectively injecting a DLL and hooking the functions you need is IMO the better solution. More complicated than using SetWindowHookEx, but will not have the overhead and annoying problems that are associated with global hooks...IE getting the mouse stuck on your horizontal plane, which I think is not what is to happen.
Wouldn't he still need to use a hook to modify the mouse-input messages? I mean, the coords "encoded" in the message params probably come from somewhere else than GetCursorPos, do they not? Wouldn't btw selectively injecting the DLL instead of trying this globally with every process make it less "global"?
> The problem with computers is that they do what you tell them to do and not what you want them to do. < > "It doesn't work, fix it" does not qualify as a bug report. < > Amazing what new features none of the programmers working on the project ever heard of you can learn about when reading what the marketing guys wrote about it. <
-
Wouldn't he still need to use a hook to modify the mouse-input messages? I mean, the coords "encoded" in the message params probably come from somewhere else than GetCursorPos, do they not? Wouldn't btw selectively injecting the DLL instead of trying this globally with every process make it less "global"?
> The problem with computers is that they do what you tell them to do and not what you want them to do. < > "It doesn't work, fix it" does not qualify as a bug report. < > Amazing what new features none of the programmers working on the project ever heard of you can learn about when reading what the marketing guys wrote about it. <
He could hook the actual function it self by using a DLL, messy but could work well and to make this global you can keep an array of processes and check for new ones and inject into the new ones. Or, looking back at what you have said another way to do it would be to use SetWindowHookEx and pass the thread ID of the process that is to be injected into. [^] I just feel that this particular program could cause problems in other programs if it were a global hook, and that it only needs to be applied to specific processes rather than all running processes. From the example of the op with mspaint. Also the call chain for GetCursorPos is: GetCursorPos -> NtUserCallOneParam( DWORD dwParam, DWORD routine ) So, a hook on NtUserCallOneParam could be used to modify the mouse position that is returned.
-
HHOOK WINAPI SetWindowsHookEx(
__in int idHook,
__in HOOKPROC lpfn,
__in HINSTANCE hMod,
__in DWORD dwThreadId
);http://msdn.microsoft.com/en-us/library/ms644990(VS.85).aspx[^] and then look at: WH_MOUSE or WH_MOUSE_LL to get what you need. WH_MOUSE_LL gives a little bit more information, but may not be needed in your application.
Thanks for the answer. I could use one more hint. To modify the mouse data with let's say WH_MOUSE_LL I have to use my own custom CallBack function and modify the POINT pt of the MSLLHOOKSTRUCT pointed to by lParam, which has been passed to the CallBack function, right? Or did I get something wrong about how to restrict the movement correctly?
-
Thanks for the answer. I could use one more hint. To modify the mouse data with let's say WH_MOUSE_LL I have to use my own custom CallBack function and modify the POINT pt of the MSLLHOOKSTRUCT pointed to by lParam, which has been passed to the CallBack function, right? Or did I get something wrong about how to restrict the movement correctly?
If i remember correctly yes that would be how you would restrict the movement.