using System; using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; namespace BiskLog_Point_Of_Sale.Classes { public class lastIdle { [StructLayout(LayoutKind.Sequential)] struct LASTINPUTINFO { public static readonly int SizeOf = Marshal.SizeOf(typeof(LASTINPUTINFO)); [MarshalAs(UnmanagedType.U4)] public int cbSize; [MarshalAs(UnmanagedType.U4)] public UInt32 dwTime; } [DllImport("user32.dll")] static extern bool GetLastInputInfo(ref LASTINPUTINFO plii); public static int GetLastInputTime() { int nIdleTime = 0; LASTINPUTINFO liiInfo = new LASTINPUTINFO(); liiInfo.cbSize = Marshal.SizeOf(liiInfo); liiInfo.dwTime = 0; int nEnvTicks = Environment.TickCount; if (GetLastInputInfo(ref liiInfo)) { int nLastInputTick = int.Parse(liiInfo.dwTime.ToString()); nIdleTime = nEnvTicks - nLastInputTick; } return ((nIdleTime > 0) ? (nIdleTime / 1000) : nIdleTime); } } }