http://www.pinvoke.net/default.aspx/user32.GetLastInputInfo
[StructLayout(LayoutKind.Sequential)]
public struct LASTINPUTINFO
{
  [MarshalAs(UnmanagedType.U4)]
  public int cbSize;
  [MarshalAs(UnmanagedType.U4)]
  public uint dwTime;
}

static class NativeMethods
{
   /// <summary>
   /// 获取上一次输入的时间。
   /// </summary>
   /// <param name="plii"></param>
   /// <returns>true:获取成功。false:获取失败。</returns>
   [DllImport("user32.dll")]
   public static extern bool GetLastInputInfo(ref LASTINPUTINFO plii);
   /// <summary>
   /// 获取上一次操作后的闲置时间。
   /// </summary>
   /// <returns>闲置时间的毫秒数。</returns>
    public static long GetIdleTick()
    {
         LASTINPUTINFO vLastInputInfo = new LASTINPUTINFO();
         vLastInputInfo.cbSize = Marshal.SizeOf(vLastInputInfo);
         if (!GetLastInputInfo(ref vLastInputInfo)) return 0;
         return Environment.TickCount - (long)vLastInputInfo.dwTime;
    }
}

相关文章:

  • 2021-10-20
  • 2020-11-03
  • 2022-03-02
  • 2021-06-06
  • 2022-01-23
  • 2022-01-14
  • 2022-02-10
  • 2022-02-10
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-02-10
  • 2022-02-14
相关资源
相似解决方案