/// <summary> /// 获取上次键盘或者鼠标移动到现在的毫秒数 /// </summary> /// <returns>返回上次键盘或者鼠标移动到现在的毫秒数</returns> public static long GetLastInputTime() { Lastinputinfo structure = new Lastinputinfo(); structure.cbSize = Marshal.SizeOf(structure); if (!GetLastInputInfo(out structure)) { return 0L; } return (Environment.TickCount - structure.dwTime); }
public static extern bool GetLastInputInfo(out Lastinputinfo plii);