VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



How to detect system activity for mouse and keyboard

by Submitted by Gcruz, Auhor: Andrea Rossignoli (1 Submission)
Category: Windows API Call/Explanation
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Sun 20th October 2002
Date Added: Mon 8th February 2021
Rating: (1 Votes)

How to detect system activity for mouse and keyboard

Rate How to detect system activity for mouse and keyboard



' http://www.andreavb.com/tip020016.html
Option Explicit

'===========================================================
'TYPE
'===========================================================
Private Type POINTAPI
x As Integer
y As Integer
End Type
'===========================================================
'API
'===========================================================
Private Declare Sub GetCursorPos Lib "user32.dll" (lpPoint As POINTAPI)
Private Declare Function GetAsyncKeyState Lib "user32.dll" (ByVal vKey As Long) As Integer
'===========================================================
'Variables
'===========================================================
Private posOld As POINTAPI
Private posNew As POINTAPI
 

'Module 

 '===========================================================
'InputCheck
'===========================================================
Public Function InputCheck() As Boolean
    Dim i As Integer

   'Get the current mouse cursor coordinates
    Call GetCursorPos(posNew)
    'Compare with old coordinates
    If ((posNew.x <> posOld.x) Or (posNew.y <> posOld.y)) Then
        posOld = posNew
        InputCheck = True
        Exit Function
    End If
    'Check keys state
    For i = 0 To 255
        If (GetAsyncKeyState(i) And &H8001) <> 0 Then
            InputCheck = True
            Exit Function
        End If
    Next i
    InputCheck = False
End Function

'Usage 

 'Create a Form with a Label and a Timer
Option Explicit

Private Sub Timer1_Timer()
    Label1.Caption = InputCheck
End Sub


Download this snippet    Add to My Saved Code

How to detect system activity for mouse and keyboard Comments

No comments have been posted about How to detect system activity for mouse and keyboard. Why not be the first to post a comment about How to detect system activity for mouse and keyboard.

Post your comment

Subject:
Message:
0/1000 characters