修改获取键盘和鼠标没有操作时间

This commit is contained in:
马巧 2025-10-13 09:50:46 +08:00
parent 33cbdb530e
commit e12f4ccbcd
1 changed files with 11 additions and 3 deletions

View File

@ -1,4 +1,9 @@
using System;
using DM_Weight.Port;
using DM_Weight.ViewModels;
using log4net;
using log4net.Core;
using log4net.Repository.Hierarchy;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
@ -9,6 +14,7 @@ namespace DM_Weight.util
{
public class CheckComputerFreeState
{
private static readonly ILog logger = LogManager.GetLogger(typeof(CheckComputerFreeState));
/// <summary>
/// 创建结构体用于返回捕获时间
/// </summary>
@ -52,15 +58,17 @@ namespace DM_Weight.util
long currentTick = Environment.TickCount64;
long lastInputTick = vLastInputInfo.dwTime;
logger.Info($"获取用户未操作时间间隔{currentTick}-{lastInputTick}");
// 处理可能的回绕(虽然使用 64 位后极不可能发生)
if (currentTick < lastInputTick)
{
// 发生了回绕,调整计算
lastInputTick -= uint.MaxValue + 1L;
}
long elapsedMilliseconds = currentTick - lastInputTick;
return Math.Max(0, elapsedMilliseconds / 1000);
long seconds = elapsedMilliseconds / 1000;
logger.Info($"获取用户未操作时间间隔{currentTick}-{lastInputTick}-{elapsedMilliseconds}-{seconds}-{Math.Max(0, seconds)}");
return Math.Max(0, seconds);
}
}
}