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

  • 相关阅读:
    JAVA基础-多态
    JAVA基础-- 对象转型 (casting)
    Flutter: 下拉刷新,上拉加载更多
    Flutter 创建dashboard页面
    Android Studio 3.3.1 向avd模拟器发送本地文件
    Flutter 真机调试
    android adb命令,向开发手机添加文件
    获取用户在web页面上选中的文本
    Cheat Engine 6.8 设置中文
    Flutter 编写内联文本
  • 原文地址:https://www.cnblogs.com/fromchaos/p/2658497.html
Copyright © 2011-2022 走看看