- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?
a QuickWin program? Also can I set the cursor position by program?
Link Copied
5 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Use the following to get mouse position:
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:
HTH
Jugoslav
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- 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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Using SetCursorPos seem to solve the problem nicely!
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page