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

  • 相关阅读:
    多屏共享
    md5-linux_shell
    2017年会所得
    linux无线网络配置_转
    (转)台式机华硕主板双显卡切换,怎么舒服怎么来
    Apache FtpServer 实现文件的上传和下载
    (转载)Windows 上搭建Apache FtpServer
    Eclipse常用设置
    博客园文章样式修改
    黑马公社学习
  • 原文地址:https://www.cnblogs.com/fromchaos/p/2658497.html
Copyright © 2011-2022 走看看