调用下面代码的GetIdleTick()方法,就可以获得键盘鼠标无操作的时间,单位为毫秒
\n首先要using System.Runtime.InteropServices;
///\n/// 获取鼠标键盘空闲时间\n///\n///\npublic static long GetIdleTick()\n{\nLASTINPUTINFO lastInputInfo = new LASTINPUTINFO();\nlastInputInfo.cbSize = Marshal.SizeOf(lastInputInfo);\nif (!GetLastInputInfo(ref lastInputInfo)) return 0;\nreturn Environment.TickCount - (long)lastInputInfo.dwTime;\n}\n[StructLayout(LayoutKind.Sequential)]\nprivate struct LASTINPUTINFO\n{\n[MarshalAs(UnmanagedType.U4)]\npublic int cbSize;\n[MarshalAs(UnmanagedType.U4)]\npublic uint dwTime;\n}\n///\n/// 调用windows API获取鼠标键盘空闲时间\n///\n///\n///\n[DllImport("user32.dll")]\nprivate static extern bool GetLastInputInfo(ref LASTINPUTINFO plii);\n