Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

VB6 - Idle Time

Posted on 2014-04-27
6
Medium Priority
?
972 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 28

Accepted Solution

by:
MacroShadow earned 2000 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 46

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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 46

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

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

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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 Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses
Course of the Month14 days, 13 hours left to enroll

577 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