Solved

VB6 - Idle Time

Posted on 2014-04-27
6
758 Views
Last Modified: 2014-04-29
Hi guys

I need to know when the computer enters idle time - ie no keyboard input etc ... without installing a system hook ... as I recall, there is an API which can help me with this ... Can someone point me in the right direction or provide a good example?

MTIA

DWE
0
Comment
Question by:dwe0608
  • 3
  • 2
6 Comments
 
LVL 27

Accepted Solution

by:
MacroShadow earned 500 total points
ID: 40025651
hmmm...

Not sure this is such a good idea. The fact that there was no user input doesn't mean that the computer is idle, it way be running a task in the background such as software updates etc.

If you insist, I think the API's you're after are:
GetLastInputInfo

Here is a sample from http://www.vbforfree.com/detecting-if-the-user-is-active-or-idle-systemwide/:
'The actual API call to use.
Private Declare Function GetLastInputInfo Lib "user32.dll" (ByRef inputStructure As inputInfo) As Boolean

Private Type inputInfo
    structSize As Long
    tickCount As Long
End Type

Private Sub Timer1_Timer()

    'The variable that will be passed to the API call and receive the activity report.
    Private info As inputInfo
    '
    'Visual Basic 5.0/6.0…
    Dim firstTick As Long
    Dim lastTick As Long

    'This timer will fire every 1000ms(One Second) or so displaying the last time the user was active.
    '
    'The size of the structure for the API call.
    info.structSize = Len(info)
    '
    'Call the API.
    GetLastInputInfo (info)
    '
    'Compare the tickcount values to determine if activity has occurred or not.
    If firstTick <> info.tickCount Then
        '
        'Display the current time of the users last activity.
        '
        'Change lblTime.Caption to lblTime.Text if using .NET and likewise change Time
        'to Now instead.
        lblTime.Caption = "Last Active: " & Time
        '
        'Get the new tick value.
        firstTick = info.tickCount
    End If

End Sub

Open in new window

0
 
LVL 45

Expert Comment

by:aikimark
ID: 40026020
the computer enters idle time
I assume that you want your application to know when the system is about to enter standby/hibernate mode.  Is that correct?

SystemParametersInfoSS will allow you to tell if the screen saver is running.

There is another API, SetWindowLong, that should tell your application when this happens.  It works via a callback (you pass it a routine -- AddressOf() -- when you invoke the API and the API then invokes the routine as necessary).  This is a system 'hook' of sorts that causes the routine of your choice to receive system messages.  You would want to check for POWERBROADCAST (&h218) messages, maybe others.
0
 
LVL 1

Author Comment

by:dwe0608
ID: 40026198
Hi guys, thanks for the input. The reason I am looking into the idle time and that my application is part of a Time Billing program, aimed largely at keeping the time people work at their computers. If a timer is running and there is no keyboard or mouse input for an extended period hen I need to factor that into my calculations ...

I think MacroShadows input is close to what I am looking for ...
0
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.

 
LVL 45

Expert Comment

by:aikimark
ID: 40026205
Are you only measuring activity within your application or any/all application(s) on the PC?
0
 
LVL 1

Author Comment

by:dwe0608
ID: 40026242
All applications - systemwide ... the final objective will be to allow the user to keep the idle time as part of the billing process or deduct it as a legitimate deduction from the total time.

Using MacroShadows example, the keyword GetLastInputInfo yielded a small project in similar terms to his example code - attached is the example.

Many thanks for the input ...
getLastUserActivity.zip
0
 
LVL 1

Author Comment

by:dwe0608
ID: 40030513
I've requested that this question be closed as follows:

Accepted answer: 400 points for MacroShadow's comment #a40025651
Assisted answer: 100 points for aikimark's comment #a40026020
Assisted answer: 0 points for dwe0608's comment #a40026242

for the following reason:

my comment has a complete coded project for future user
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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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 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…
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…

914 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

19 Experts available now in Live!

Get 1:1 Help Now