Solved

Detecting mouse/keyboard activity

Posted on 1999-01-08
5
271 Views
Last Modified: 2010-05-03
this has probably been asked before...
I need to detect mouse/keyboard activity, not just on the current window(form) but ANY window in the windows enviroment. are there API's to do this? or would i have to get a 3rd party component. I have a timer on my current project that if the user is not doing ANYTHING on the computer to timeout and bring up a password to log back into the program. so I need to detect any type of action on computer.

TIA
0
Comment
Question by:jalleman
5 Comments
 
LVL 15

Expert Comment

by:ameba
ID: 1454902
For mouse activity, you can use GetCursorPos API and timer loop.
But, what you want, looks more like screen server app.

0
 
LVL 18

Expert Comment

by:mdougan
ID: 1454903
Not a bad suggeston.  Why not create a screensaver application that pops a dialog forcing the user to log in.  Better yet, why not use the one that comes with Windows?

MD
0
 

Author Comment

by:jalleman
ID: 1454904
Don't think I can use the screen saver. what if they don't have the screen saver set? or passworded? will go with the GetCurserPos API and have the program passworded. Now, to figure out that works :-)
0
 
LVL 15

Expert Comment

by:ameba
ID: 1454905
' add timer, set interval to 2000
Option Explicit
Private Type POINTAPI
        x As Long
        y As Long
End Type
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Dim gUseIt As Boolean ' if true inputbox will show after x sec
Dim sleepCounter As Long
Dim sleepX As Single
Dim sleepY As Single
Dim gNumPeriods As Long

Private Sub Form_Load()
    gUseIt = True
    gNumPeriods = 4 ' 8 seconds
End Sub

' this timer should be on your main form, e.g. MDI
Private Sub Timer1_Timer()
    Dim p As POINTAPI
    On Error GoTo sleeperr
    If gUseIt = -1 Then
        Call GetCursorPos(p)
        Debug.Print p.x & " " & p.y
        If p.x = sleepX And p.y = sleepY Then
            ' cursor position is the same
            sleepCounter = sleepCounter + 1
            If sleepCounter >= gNumPeriods Then
pwtry:
                If InputBox("Password", "Title", "") = "pwd" Then
                    ' allow new wait period
                    sleepCounter = 0
                Else
                    ' punishment for bad pwd
                    MsgBox "Bad pwd"
                    '... code to check number of retries
                    GoTo pwtry
                End If
            End If
        Else
            ' cursor position is NOT the same, reset timing
            sleepX = p.x
            sleepY = p.y
            sleepCounter = 0
        End If
        Debug.Print sleepCounter
    Else
        sleepCounter = 0
        Timer1.Enabled = False
    End If
    Exit Sub
sleeperr:
    sleepCounter = 0
    Exit Sub
End Sub

0
 
LVL 3

Accepted Solution

by:
myqlG earned 200 total points
ID: 1454906
The answer is this.. You CANNOT detect these things without
a system wide hook like.. msghook.dll or easyhook.dll.
The only application I can think of would be a trojan horse
of some kind.. so if you email me a GOOD reason I will provide
you with a URL that has all the info or a sample .vbp
michael@nppn.net
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
vba is buggy because of corrupted user profile. Any fast way to fix it? 28 127
Write data from SQL to CSV file - position 1 52
Using "ScreenUpdating" 6 55
Spell Check in VB6 13 96
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now