This code can be used to determine the X,Y coordinates of the mouse cursor
and use them to check for idle mouse activity. This code is useful in that it does
not require your current form to be in focus (active windows status). The
GetCursorPos can be used in conjunction with or be replaced by another API
call GetCaretPos, which determines the X,Y coordinates of the text cursor.
Hopefully this will be useful to anyone looking to check for an idle desktop.
(Richard Puckett, [email protected])
Assumes
1. Take out all of the ME.PRINT statements, since they are only to illustrate how
the function works (I used this code in a login program to monitor mapped
network drive connections in lab environments.) 2. All of the declarations are
in a module. 3. This example is only using the X coords to determine activity, I
am sure a more complex method can be devised.
API Declarations'API Call establishes mouse coords
Public Declare Function GetCursorPos Lib "user32" _
(lpPoint As PointAPI) As Long
Public Pnt As PointAPI
'These values MUST be public
Public OldX As Long
Public OldY As Long
Public NewX As Long
Public NewY As Long
Public Type PointAPI
X As Long
Y As Long
End Type
'This Const determines the total timeout value in minutes
Global Const MINUTES = 15
Public TimeExpired
Public ExpiredMinutes