Software Archive
Read-only legacy content
17060 Discussions

Disconnecting mouse cursor from mouse

alfredodell
Beginner
409 Views
I want to read mouse input without the cursor moving. How I do this from
a QuickWin program? Also can I set the cursor position by program?
0 Kudos
5 Replies
Jugoslav_Dujic
Valued Contributor II
409 Views
Use the following to get mouse position:
 
USE DFWIN 
TYPE(T_POINT):: PT 
iSt = GetCursorPos(PT) 
iSt = ScreenToClient(GETHWNDQQ(YourWindow), PT). 
iX = PT%x 
iY = PT%y 


ScreenToClient converts from screen-coordinates into YourWindow-relative coordinates. To set position, use SetCursorPos (and ClientToScreen if necessary).
Additionally, you can check status of mouse button (or any key from keyboard)
using:
 
IF (IAND(GetKeyState(MK_LBUTTON), #8000).NE.0) THEN !Left button pressed 


HTH

Jugoslav
0 Kudos
alfredodell
Beginner
409 Views
I have no problem with reading mouse cursor position (I am doing it by
intercepting messages to the window). The problem lies in preventing mouse
position change information from updating the mouse cursor whilst being
able to read the change information to enable me to control program behaviour.
0 Kudos
Jugoslav_Dujic
Valued Contributor II
409 Views
Ah, I see -- you want the pointer to stay fixed while user is moving the mouse and read that moving? Well, I know half of the answer -- use ClipCursor to fix the cursor to a certain point (don't forget to call it again with NULL parameter to restore normal behaviour).

As for catching mouse events in that state -- I don't know. Two ideas come to my mind:

1) ClipCursor to a 3x3 points region. When WM_MOUSEMOVE arrives, check where it actually moved (up/down, left/right) and after processing reset its position back to the center using SetCursorPos. In this way you should receive a series of "micro" moves which you could track and process.

2) If it fails, try installing a low-level mouse hook (SetWindowsHookEx(WH_MOUSE_LL)) (NT/2000/XP only). See a sample on instaling hook (search for SetWindowsHookEx in the Forum). Take a look into SetWindowsHookEx and LowLevelMouseProc in Win32 SDK docs.

HTH

Jugoslav
0 Kudos
Jugoslav_Dujic
Valued Contributor II
409 Views
Well, I tried it myself (approach 1). It looks as if ClipCursor is not necessary (and it didn't work well in my program since I got a sluggish response). The algorithm is approximately:

- When an action "enter fixed-cursor mode" occurs, store original mouse X/Y. Reset a pair iAccX/iAccY (accumulated) to zero. Original X/Y and iAccX/Y should have SAVE attribute.

- When mouse moves in that mode, add the difference of current position and original X/Y to iAccX/iAccY. That tells you how much the user moved the mouse (on mousepad). Do something with that. Call ClientToScreen and SetCursorPos to move the cursor back to original X/Y.


That caused the cursor to vibrate slightly (since my "Do something" was a rather long operation); I don't know whether something could be done about it.

Jugoslav
0 Kudos
alfredodell
Beginner
409 Views
Using SetCursorPos seem to solve the problem nicely!
0 Kudos
Reply