Solved

VB6 - Idle Time

Posted on 2014-04-27
6
830 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
[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
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

733 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