Solved

Detecting mouse/keyboard activity

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…
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…
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…

743 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