?
Solved

Detecting mouse/keyboard activity

Posted on 1999-01-08
5
Medium Priority
?
279 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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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

800 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