Solved

VB6 - Idle Time

Posted on 2014-04-27
6
680 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 26

Accepted Solution

by:
MacroShadow earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 45

Expert Comment

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

Author Comment

by:dwe0608
Comment Utility
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
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

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…
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…
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…

772 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

13 Experts available now in Live!

Get 1:1 Help Now