How to check the Idle time of Windows application

Shaila

New member
Joined
Oct 13, 2006
Messages
3
Programming Experience
1-3
I want to check if my application is being used or not. If my application is not used for say 10 mins, i need to lock my application. My application is developed in VB.NET. Is there any way to check the status (Active/Inactive) of windows based application.

Thanks in advance..
 

vis781

Well-known member
Joined
Aug 30, 2005
Messages
2,015
Location
Cambridge, UK
Programming Experience
5-10
Code:
Private Declare Function GetLastInputInfo Lib "user32.dll" (ByRef plii As LASTINPUTINFO) As Int32
 
<StructLayout(LayoutKind.Sequential)> _
Private Structure LASTINPUTINFO
 
cbSize As Int32
dwTime As Int32
 
End Structure
Those are the API's you will need. I havent used them myself but basically dwtime is the count since the last mouse or keyboard interaction.
 

Shaila

New member
Joined
Oct 13, 2006
Messages
3
Programming Experience
1-3
As per the code mentioned by u, dwTime will change even when there is a mouse/key board movement done on any other file. But i want to check, only my application status. I might be doing some thing else on my machine, but i might not be using my application. In that case i need to lock my application.

The code mentioned by you will be useful..if i need to lock my computer itself.

Please do let me know if there is any other way of handling this problem..
 

vis781

Well-known member
Joined
Aug 30, 2005
Messages
2,015
Location
Cambridge, UK
Programming Experience
5-10
In that case you this by implementing the IMessageFilter interface to listen to messages that are specific to your applications message loop. I haven't got the time to check into the windows messages you wil need. But basically a timer needs to start when your application stops recieving the WM_KEYDOWN and WM_MOUSE messages. When the timer reaches the 10 minutes lock the application. There is also i believe a function in Kernal32.dll that can get a tick count, you could use that instead of a custom timer.
 

Shaila

New member
Joined
Oct 13, 2006
Messages
3
Programming Experience
1-3
Thanx a lot..This worked for me...I implemented IMessageFilter interface and wrote my logic in PreFilterMessage method.
 

prabodh

New member
Joined
Dec 4, 2009
Messages
1
Programming Experience
1-3
I want it too

Could you plz share the code sample of how did u do that?
 
Top Bottom