renjith
asked on
Tracking system idle time
I am creating a component that has to do windows screen lock based on the system idle time.
Say if the system is idle for 15 mins it should lock the screen. How can I track the system idle time ?
Is there any readymade utility for this ?
Regards
Renjith
Say if the system is idle for 15 mins it should lock the screen. How can I track the system idle time ?
Is there any readymade utility for this ?
Regards
Renjith
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
using System;
using System.Runtime.InteropServ
namespace Test1
{
class Class1
{
[StructLayout(LayoutKind.S
struct LASTINPUTINFO
{
public int cbSize;
public int dwTime;
}
[DllImport ("User32.dll")]
static extern void GetLastInputInfo(ref LASTINPUTINFO info);
[DllImport ("Kernel32.dll")]
public static extern int GetTickCount();
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
LASTINPUTINFO info = new LASTINPUTINFO();
info.cbSize = Marshal.SizeOf(info);
GetLastInputInfo(ref info);
int n = GetTickCount();
int nIdle = n - info.dwTime;
Console.WriteLine("Idele time (ms): {0}", nIdle);
}
}
}