Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Detecting mouse/keyboard activity

Posted on 1999-01-08
5
Medium Priority
?
281 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 400 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
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…
Suggested Courses

598 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