Solved

Detecting mouse/keyboard activity

Posted on 1999-01-08
5
273 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

813 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

10 Experts available now in Live!

Get 1:1 Help Now