• 系统空闲时间 解决 GetLastInputInfo 负数问题


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.InteropServices;
    using System.Text;
    using System.Threading.Tasks;

    namespace ATMDefendCabinEventVideoForm
    {
    public class CheckComputerFreeState
    {

    /// <summary>
    /// 创建结构体用于返回捕获时间
    /// </summary>
    [StructLayout(LayoutKind.Sequential)]
    struct LASTINPUTINFO
    {
    /// <summary>
    /// 设置结构体块容量
    /// </summary>
    [MarshalAs(UnmanagedType.U4)]
    public int cbSize;

    /// <summary>
    /// 抓获的时间
    /// </summary>
    [MarshalAs(UnmanagedType.U4)]
    public uint dwTime;
    }

    [DllImport("user32.dll")]
    private static extern bool GetLastInputInfo(ref LASTINPUTINFO plii);
    /// <summary>
    /// 获取键盘和鼠标没有操作的时间
    /// </summary>
    /// <returns>用户上次使用系统到现在的时间间隔,单位为秒</returns>
    public static long GetLastInputTime()
    {
    LASTINPUTINFO vLastInputInfo = new LASTINPUTINFO();
    vLastInputInfo.cbSize = Marshal.SizeOf(vLastInputInfo);
    if (!GetLastInputInfo(ref vLastInputInfo))
    {
    return 0;
    }
    else
    {
    Console.WriteLine("TickCount=" + Environment.TickCount);
    Console.WriteLine("vLastInputInfo.dwTime=" + vLastInputInfo.dwTime);
    Console.WriteLine("vLastInputInfo.dwTime & Int32.MaxValue=" + (vLastInputInfo.dwTime & Int32.MaxValue));
    var count = Environment.TickCount & Int32.MaxValue - (long)(vLastInputInfo.dwTime & Int32.MaxValue);
    var icount = count / 1000;
    return icount;
    }
    }


    public static long GetLastInputTimeMinute()
    {
    LASTINPUTINFO vLastInputInfo = new LASTINPUTINFO();
    vLastInputInfo.cbSize = Marshal.SizeOf(vLastInputInfo);
    if (!GetLastInputInfo(ref vLastInputInfo))
    {
    return 0;
    }
    else
    {
    var count = Environment.TickCount - (long)vLastInputInfo.dwTime;
    var icount = count / (1000*60);
    return icount;
    }
    }

    }
    }

  • 相关阅读:
    show point on image
    vec2d
    Size类型如何调用和定义
    opencv数据类型和格式的坑
    IplImage 与mat之间的转换及释放内存
    linux平台程序高精度延时问题select-usleep等
    gettimeofday的使用
    列模式编辑文本
    【linux基础】如何开机自启动某个程序-linux工具-ubuntu
    查看camera设备-linux
  • 原文地址:https://www.cnblogs.com/bkyrslf/p/9451212.html
Copyright © 2020-2023  润新知