Here's a similar solution using Windows API GetCursorPos() to determine inactivity. I was unable to find an API 'Mouse Move Event' so instead a timer is used to poll the cursor position every few seconds. When a timeout occurs, the file is saved, a wscript message is displayed, and Excel is terminated just like in the previous post.
The following items at the top of 'ModCursorMovement' can be changed to fine tune 'Lack of Cursor Movement Detection':
a. Conditional Compilation Constant 'NEED_TO_DEBUG' - Set 'True' for PRODUCTION and set to 'False' for SOFTWARE DEVELOPMENT.
b. Const 'jDeltaMaxForNoMOVEMENT' to determine 'cursor position sensitivity (e.g. 5 means Delta of 5 pixels means position DID NOT MOVE).
c. Const 'jMaxSecondsOfInactivityALLOWED' to determine TIMEOUT VALUE (e.g. 120 seconds is 2 minutes).
d. Const 'jSecondsBetweenSAMPLES' to determine how often the cursor position is sampled.
When in SOFTWARE DEVELOPMENT mode the debugger 'Immediate Window' (CTRL G) contains POSITION data.
Code follows and is included in the attached file.
Lewis
ThisWorkbook Module:
Ordinary Module ModCursorMovement:
Ordinary Code modeule LjmTimers:
Bookmarks