VBA Record Mouse Motion

jeff_

New Member
Joined
Jun 11, 2016
Messages
3
Hi,

I would like to record the mouse motion, even when it goes off the screen. I can set up a timer and get the screen position of the mouse with Function GetCursorPos Lib "user32", but I'm trying to build a mouse tracker for physical measurement beyond what the display can see. Does anyone have any ideas?

I've been scouring the web for calls to record the raw mouse messages, but I can't find anything in VBA, which is the extent of my abilities.

I'm just looking to write the motion messages from the mouse to a cell, or cells for x and y, so I can log and track it.

Thanks in advance.
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.


Thank you. I like this code better than my timer based one. I especially didn't know about DoEvents. It is still limited by the function call GetCursorPos() which only feeds back where the mouse is on the display. I'm hoping to get the raw movement data from the mouse. I'm sure Windows gets an interrupt from the mouse device when movement is detected or button events happen. Maybe there is an HID call or I need to do this from the command line. Thank you again!
 
Upvote 0
Understood that the mouse icon you view cannot go beyond the display, but the physical mouse you drag around can. That's the data I'm trying to get to.
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,917
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top