Log inUsernamePassword
Log me on automatically each visit    
Register
Register
Log in to check your private messages
Log in to check your private messages
Visual Basic Forum for Visual Basic Programmers VB Forum Index » Knowledge Base

Post new topic   Reply to topic
PC Idle Monitor
View previous topic :: View next topic  
Author Message
Avis
Junior Poster


Joined: 07 Oct 2003
Posts: 510
Location: India

PostPosted: Aug 2nd, 2004 07:05 AM    Post subject: PC Idle Monitor Reply with quote

This module allows you to determine how long your computer has been Idle. It checks to see if a key was pressed or if the mouse has moved.

[vb:1:bd5b63e601]Option Explicit

Public Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer

Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long

Public Type POINTAPI
X As Long
Y As Long
End Type

Public Function CheckIdleState()As String

Dim kKey As Integer 'Stores Each Key on the keyboard in the For Next Loop
Dim CurrentMousePos As POINTAPI 'Used To store the current mouse position
Static OldMousePos As POINTAPI 'Static-keeps the old mouse position
Static IdleTime As Date 'Stores the time In a date variable
Dim SystemIdle As Boolean'Stores weather the systme is idle or Not
SystemIdle = True 'Sets the idle value To true

For kKey = 1 To 256 'steps through Each key on the keyboard it detect If

If GetAsyncKeyState(kKey) <> 0 Then 'any of the keys have been pressed
Debug.Print "Key Pressed"
SystemIdle = False 'Sets the idle value To false
Exit For 'Exits the for Next Loop so that it will move on To the next step
End If

Next

GetCursorPos CurrentMousePos 'Gets the current cursor position and stores it
If CurrentMousePos.X <> OldMousePos.X Or _
CurrentMousePos.Y <> OldMousePos.Y Then 'Checks To see If the cursor has moved
Debug.Print "Mouse Moved"
SystemIdle = False'since the last time it was checked
End If

OldMousePos = CurrentMousePos 'Stores the current mouse position For comparring positons the
'next time through

If SystemIdle = True Then 'If a key hasn't been pressed and the mouse hasn't moved

If DateDiff("s", IdleTime, Now) >= 60 Then 'it sets the return value To the elapsed time value
IdleTime = Now 'Resets the time To check the Next minute For idle
CheckIdleStaate = CheckIdleState + 1 'sets the return value In minutes of being idle
End If

Else
IdleTime = Now 'Sets the new Current Idle Time To check For elapsed time
End If

End Function[/vb:1:bd5b63e601]
_________________
Code Snippets, Tutorials, Utilities, Controls

Low cost Web Hosting
Hosting starts at as low as $4 per year!


Always follow posting guidelines
Put your VB code in [vb ] your code [ /vb] tags!
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger ICQ Number
vbman995
Moderator


Joined: 19 Aug 2005
Posts: 264
Location: Planet Earth

PostPosted: Jan 25th, 2006 07:45 PM    Post subject: Reply with quote

Pretty Neat code, I might need it for this project im working on.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Visual Basic Forum for Visual Basic Programmers VB Forum Index » Knowledge Base All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Visual Basic Forum runs phpBB | Forum Template © iOptional
VB Resources | SSL | Visual Basic