public bool IsWorkingOnPC() { WinAPI.LASTINPUTINFO lastInputInfo = new WinAPI.LASTINPUTINFO(); lastInputInfo.cbSize = (uint)Marshal.SizeOf(lastInputInfo); WinAPI.GetLastInputInfo(ref lastInputInfo); var idieTime = TimeSpan.FromMilliseconds(Environment.TickCount - lastInputInfo.dwTime); if (idieTime.TotalSeconds > moyuConfig.MaxNoActionTime) { return(false); } return(true); }
public static int GetLastInputSeconds() { var plii = new WinAPI.LASTINPUTINFO(); plii.cbSize = (uint)Marshal.SizeOf(plii); if (WinAPI.GetLastInputInfo(ref plii)) { var lastInputTime = TimeSpan.FromMilliseconds(Environment.TickCount - plii.dwTime).TotalSeconds; return((int)lastInputTime); } else { throw new System.ComponentModel.Win32Exception(Marshal.GetLastWin32Error()); } }