Exemplo n.º 1
0
 public InputWatcher(double interval)
 {
     // 必须将结构体的cbSize设置为结构体的大小(sizeof(LastInputInfo))
     // https://docs.microsoft.com/en-us/windows/desktop/api/winuser/ns-winuser-taglastinputinfo
     LastInputInfo        = new DLLInvoke.LastInputInfo();
     LastInputInfo.cbSize = Marshal.SizeOf(LastInputInfo);
     Timer = new Timer
     {
         Interval  = interval,
         AutoReset = true
     };
 }
Exemplo n.º 2
0
        /// <summary>
        /// 获取最后一次输入距现在的毫秒值
        /// </summary>
        /// <param name="lastInputInfo"></param>
        /// <returns></returns>
        public static uint GetLastInputTimeInterval(ref DLLInvoke.LastInputInfo lastInputInfo)
        {
            uint inputInterval = 0;

            if (DLLInvoke.GetLastInputInfo(ref lastInputInfo) != 0)
            {
                inputInterval = DLLInvoke.GetTickCount() - lastInputInfo.dwTime;
                if (inputInterval < 0)
                {
                    inputInterval = 0;
                }
            }
            return(inputInterval);
        }