1

私はこれを長い間使用してきましたが、48 日後に適切なアイドル時間が得られないというバグを発見しました。

これは integer32 ビットによるものです。Environment.TickCountでは十分ではありません。

ただし、アイドル時間を取得する必要があり、GetLastInputTime() [ http://www.codeproject.com/KB/system/rtwidledll.aspx?display=PrintAll]は長く返されません。

public static int GetIdleTime()
{
    return (Environment.TickCount & Int32.MaxValue)- (int)GetLastInputTime();
}

/// <summary>
/// Get the last input time from the input devices.
/// Exception: 
/// If it cannot get the last input information then it throws an exception with 
/// the appropriate message.
/// </summary>
/// <returns>Last input time in milliseconds.</returns>
public static uint GetLastInputTime()
{
    LastInputInfo lastInPut = new LastInputInfo();
    lastInPut.BlockSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(lastInPut);
    if (!GetLastInputInfo(ref lastInPut))
    {
        throw new Exception(GetLastError().ToString());
    }

    return lastInPut.Time;
}
4

0 に答える 0