473,399 Members | 4,192 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Idle time

Hi everyone

I want to now how long the computer is idle. Is there any easy way to do
this in vb.net 2005. Before (in VB6) I checked if the mousepointer hade been
moved.

Thanks
/Nettan
Nov 8 '06 #1
7 3277
This is code someone else gave me. It detects mouse movement. I use it
to log the person out of my program if they leave it the set number of
minutes. sysLogOffSecs is the number of minutes (in seconds) I set to
log them off.
Dim MousePos As POINTAPI 'holds mouse position
Dim mdtLastKBorMouseEvent As Date
Dim mbIsIdle As Boolean
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
Call subDetectIdle()
If mbIsIdle Then
'log them off or whatever
End If
End Sub
Public Sub subDetectIdle()
Dim bIsIdle As Boolean
Dim tCurrentPos As POINTAPI
Dim lDiff As Integer

bIsIdle = True
tCurrentPos.X = CInt(Windows.Forms.Cursor.Position.X.ToString)
tCurrentPos.Y = CInt(Windows.Forms.Cursor.Position.Y.ToString)

'Mouse Moved?
If (MousePos.X <tCurrentPos.X) Or (MousePos.Y <>
tCurrentPos.Y) Then
bIsIdle = False
MousePos.X = tCurrentPos.X
MousePos.Y = tCurrentPos.Y
End If

If Not bIsIdle Then 'Not idle...
'Not idle... Update Current Time variable
mdtLastKBorMouseEvent = Now
'Make sure the module level var is set correctly
mbIsIdle = False
Else
'Currently Idle. See how long
If mbIsIdle = False Then
'Number of seconds elapsed?
lDiff =
DateDiff(Microsoft.VisualBasic.DateInterval.Second ,
mdtLastKBorMouseEvent, Now)
If lDiff >= sysLogOffSecs Then
mbIsIdle = True
End If
End If
End If
End Sub


On Wed, 8 Nov 2006 04:58:01 -0800, Nettan
<Ne****@discussions.microsoft.comwrote:
>Hi everyone

I want to now how long the computer is idle. Is there any easy way to do
this in vb.net 2005. Before (in VB6) I checked if the mousepointer hade been
moved.

Thanks
/Nettan
Nov 8 '06 #2
I forgot to add this to the declarations:

Private Structure POINTAPI
Dim X As Integer
Dim Y As Integer
End Structure
On Wed, 08 Nov 2006 07:58:55 -0500, Kevin <km******@fireacademy.org>
wrote:
>This is code someone else gave me. It detects mouse movement. I use it
to log the person out of my program if they leave it the set number of
minutes. sysLogOffSecs is the number of minutes (in seconds) I set to
log them off.
Dim MousePos As POINTAPI 'holds mouse position
Dim mdtLastKBorMouseEvent As Date
Dim mbIsIdle As Boolean
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick
Call subDetectIdle()
If mbIsIdle Then
'log them off or whatever
End If
End Sub
Public Sub subDetectIdle()
Dim bIsIdle As Boolean
Dim tCurrentPos As POINTAPI
Dim lDiff As Integer

bIsIdle = True
tCurrentPos.X = CInt(Windows.Forms.Cursor.Position.X.ToString)
tCurrentPos.Y = CInt(Windows.Forms.Cursor.Position.Y.ToString)

'Mouse Moved?
If (MousePos.X <tCurrentPos.X) Or (MousePos.Y <>
tCurrentPos.Y) Then
bIsIdle = False
MousePos.X = tCurrentPos.X
MousePos.Y = tCurrentPos.Y
End If

If Not bIsIdle Then 'Not idle...
'Not idle... Update Current Time variable
mdtLastKBorMouseEvent = Now
'Make sure the module level var is set correctly
mbIsIdle = False
Else
'Currently Idle. See how long
If mbIsIdle = False Then
'Number of seconds elapsed?
lDiff =
DateDiff(Microsoft.VisualBasic.DateInterval.Secon d,
mdtLastKBorMouseEvent, Now)
If lDiff >= sysLogOffSecs Then
mbIsIdle = True
End If
End If
End If
End Sub


On Wed, 8 Nov 2006 04:58:01 -0800, Nettan
<Ne****@discussions.microsoft.comwrote:
>>Hi everyone

I want to now how long the computer is idle. Is there any easy way to do
this in vb.net 2005. Before (in VB6) I checked if the mousepointer hade been
moved.

Thanks
/Nettan
Nov 8 '06 #3
couple of problems with that....one is it only detects mouse movements and
two its only checking your app. so if someone used ALT + TAB to change out of
ur app, your app wont receive mouse moves. also, if theyre typing, it wont
recognize that. you can use a Mouse Hook and check the length of time between
the callbacks of that, or u can check the APIs. there was a post around here
a long while back that had that, but it seems to have been deleted....
--
-iwdu15
Nov 8 '06 #4
Nettan,

I think that you first have to tell, what you call Idle, by instance the
garbage collector is busy in program Idle time, so the computer is than not
in Idle state.

Cor
"Nettan" <Ne****@discussions.microsoft.comschreef in bericht
news:0D**********************************@microsof t.com...
Hi everyone

I want to now how long the computer is idle. Is there any easy way to do
this in vb.net 2005. Before (in VB6) I checked if the mousepointer hade
been
moved.

Thanks
/Nettan

Nov 9 '06 #5
Hi

What I meen with idle is that no person is using the computer. What i'm
planning to do is to write a program to log how much time my kids is spending
at the computer.

/Nettan

"Cor Ligthert [MVP]" wrote:
Nettan,

I think that you first have to tell, what you call Idle, by instance the
garbage collector is busy in program Idle time, so the computer is than not
in Idle state.

Cor
"Nettan" <Ne****@discussions.microsoft.comschreef in bericht
news:0D**********************************@microsof t.com...
Hi everyone

I want to now how long the computer is idle. Is there any easy way to do
this in vb.net 2005. Before (in VB6) I checked if the mousepointer hade
been
moved.

Thanks
/Nettan


Nov 10 '06 #6
No, it doesn't matter if the program is minimized, it will detect
mouse movement on the computer, not just the program.
You'll have to use APIs to detect key presses.
On Wed, 8 Nov 2006 13:08:02 -0800, iwdu15 <jmmgoalsteratyahoodotcom>
wrote:
>couple of problems with that....one is it only detects mouse movements and
two its only checking your app. so if someone used ALT + TAB to change out of
ur app, your app wont receive mouse moves. also, if theyre typing, it wont
recognize that. you can use a Mouse Hook and check the length of time between
the callbacks of that, or u can check the APIs. there was a post around here
a long while back that had that, but it seems to have been deleted....
Nov 10 '06 #7
Nettan,

Maybe can you search in this newsgroup yourself for that, you are certainly
not the first one who is asking this.

http://groups.google.com/group/micro...n&lr=&ie=UTF-8

Cor

"Nettan" <Ne****@discussions.microsoft.comschreef in bericht
news:A5**********************************@microsof t.com...
Hi

What I meen with idle is that no person is using the computer. What i'm
planning to do is to write a program to log how much time my kids is
spending
at the computer.

/Nettan

"Cor Ligthert [MVP]" wrote:
>Nettan,

I think that you first have to tell, what you call Idle, by instance the
garbage collector is busy in program Idle time, so the computer is than
not
in Idle state.

Cor
"Nettan" <Ne****@discussions.microsoft.comschreef in bericht
news:0D**********************************@microso ft.com...
Hi everyone

I want to now how long the computer is idle. Is there any easy way to
do
this in vb.net 2005. Before (in VB6) I checked if the mousepointer
hade
been
moved.

Thanks
/Nettan



Nov 11 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: los | last post by:
Hi, I'm trying to create a program similar to that of Google's desktop that will crawl through the hard drive and index files. I have written the program and as of now I just put the thread to...
3
by: john | last post by:
I don't want to know what the CPU utilization is right now. I want to get the average utilization over the last, for example, hour. So I came up with a method where I would get a Process object...
19
by: Frank Rizzo | last post by:
I want to log the user out when there has been a period of inactivity in the application. The key here is inactivity of the application, not the system. I know that you can retrieve the...
3
by: Jim G | last post by:
Hi, We have a limited number of licenses to some software we have installed on our users desktops. The problem is that sometimes the users open up the application and then don't use it all day....
2
by: henk | last post by:
I have a hard time to get the idle time only from my application. (a relogin box should appear after eg 1 min, when a user switch to word and start typing for 10min, the re-login should not appear....
33
by: ram.ragu | last post by:
hi i have problem to calculate idle time of cpu and if idle time is more then i have to shut down the system. can anyone tell me the idea to so that please
5
by: sam | last post by:
hi all, i continue to footle around on my spanking new ultra 20 (1.8GHz / Opteron Model 144), gradually trying to get to grips with python and unix both. the slow print time in IDLE had...
3
by: writser | last post by:
hey all, For my study I'm writing a simple threaded webcrawler and I am trying to do this in python. But somehow, using threads causes IDLE to crash on Windows XP (with the latest python...
5
by: Russ P. | last post by:
I've been programming in python for a few years using XEmacs on Solaris and Linux. I've been thinking about trying IDLE for a long time, but either it wasn't available on my system or I...
6
by: Andreas Tawn | last post by:
I'm trying to integrate the timeout function from here http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/473878 into a long running automation script and the following code causes IDLE after...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.