I'm trying to build a quick program (or so I thought) that would lock the Y axis of your mouse when holding down a key on the keyboard, in this case the space bar.
Saw the idea from a member here and thought it'd be fun to do. Turns out the last step has been fighting me tooth and nail.
It's within the mouse hooked method (while space is being pressed) that I call Cursor.Position = New Point(Cursor.Position.X, Y). Y being the variable locked when the space key was pressed down. This should and actually does work. The problem I'm seeing has to be something with these hooks. Because you can see that it is in fact setting the cursor position then going back. It's just happening so fast you can barely catch it. My guess is it's setting the cursor to where I want, then setting it back to where it should be (when the mouse movement occurred).
is there any way around this, or am I just doing something wrong?
Saw the idea from a member here and thought it'd be fun to do. Turns out the last step has been fighting me tooth and nail.
It's within the mouse hooked method (while space is being pressed) that I call Cursor.Position = New Point(Cursor.Position.X, Y). Y being the variable locked when the space key was pressed down. This should and actually does work. The problem I'm seeing has to be something with these hooks. Because you can see that it is in fact setting the cursor position then going back. It's just happening so fast you can barely catch it. My guess is it's setting the cursor to where I want, then setting it back to where it should be (when the mouse movement occurred).
is there any way around this, or am I just doing something wrong?
vbnet Code:
Private Function MouseProc(ByVal nCode As Int32, ByVal wParam As Int32, ByRef lParam As MSLLHOOKSTRUCT) As IntPtr If (nCode = HookCommand.ACTION) Then If LockPosition AndAlso wParam = WindowsMessage.MOUSEMOVE Then Cursor.Position = New Point(Cursor.Position.X, Y) 'SetCursorPos(x,y) ' no effect, still the same results. End If End If Return CallNextHookEx(MouseHook, nCode, wParam, lParam) End Function