-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInputTimer.cs
More file actions
31 lines (26 loc) · 771 Bytes
/
InputTimer.cs
File metadata and controls
31 lines (26 loc) · 771 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
namespace Sloth
{
public static class InputTimer
{
public static TimeSpan GetInputIdleTime()
{
var plii = new NativeMethods.LastInputInfo();
plii.cbSize = (UInt32)Marshal.SizeOf(plii);
if (NativeMethods.GetLastInputInfo(ref plii))
{
return TimeSpan.FromMilliseconds(Environment.TickCount64 - plii.dwTime);
}
else
{
throw new Win32Exception(Marshal.GetLastWin32Error());
}
}
public static DateTimeOffset GetLastInputTime()
{
return DateTimeOffset.Now.Subtract(GetInputIdleTime());
}
}
}