Detekce aktivity myši nebo klávesnice

Postup:
Option Explicit

Private Type POINTAPI
   x As Integer
   y As Integer
End Type

Private Declare Sub GetCursorPos Lib "user32.dll" _
   (lpPoint As POINTAPI)
Private Declare Function GetAsyncKeyState Lib "user32.dll" _
   (ByVal vKey As Long) As Integer

Private posOld As POINTAPI
Private posNew As POINTAPI

Public Function InputCheck() As Boolean

   Dim i As Integer

   'Zjištění aktuálních koordinátů pozice kurzoru myši
   Call GetCursorPos(posNew)

   'Porovnání s původními koordináty
   If ((posNew.x <> posOld.x) Or (posNew.y <> posOld.y)) Then
      posOld = posNew
      InputCheck = True
      Exit Function
   End If

   'Test stisknutí klávesnice - stav kláves
   For i = 0 To 255
      If (GetAsyncKeyState(i) And &H8001) <> 0 Then
         InputCheck = True
         Exit Function
      End If
   Next i

   InputCheck = False

End Function

Příklad použití:
Private Sub Timer1_Timer()

   Label1.Caption = InputCheck

End Sub

Zpět

Autor: The Bozena