VBcoders Browse New Submit Contact Sign In

No account? Register free

Forgot password?

Detect Idle Mouse (GetCursorPos)

Richard Puckett  (1 Submission)   Windows API Call/Explanation   Visual Basic 3.0   Unknown Difficulty   Wed 3rd February 2021

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

Rate Detect Idle Mouse (GetCursorPos) (4(4 Vote))
Detect Idle Mouse (GetCursorPos).bas

Detect Idle Mouse (GetCursorPos) Comments

No comments yet — be the first to post one!

Post a Comment

0/1000 characters