zoukankan      html  css  js  c++  java
  • 获取系统闲置时间

     
    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;
        }
    }

    By Peter.zhang

    From:Peter's Blog                            

    MSN: peter.zhang@live.cn

    电子邮箱:peter.zhang@foxmail.com

  • 相关阅读:
    Murano为镜像包添加Root用户密码
    Murano Weekly Meeting 2015.09.22
    Murano Weekly Meeting 2015.09.15
    Murano Weekly Meeting 2015.09.08
    Murano Deployment
    Murano Weekly Meeting 2015.09.01
    Murano Application
    Mongodb installation & userguide
    查看linux系统常用的命令,Linux查看系统配置常用命令
    SQL必知必会笔记
  • 原文地址:https://www.cnblogs.com/fromchaos/p/2658497.html
Copyright © 2011-2022 走看看