Solved

VB6 - Idle Time

Posted on 2014-04-27
6
791 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Windows 10 start screen issues 9 54
Sending a email via excel using vba 6 82
How to hault or freeze parent form when a 2d form is open in vb6 3 37
vbModal 12 51
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

776 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