forked from Matalus/MiscPS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Untitled1.ps1
60 lines (41 loc) · 1.29 KB
/
Untitled1.ps1
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Add-Type @'
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace Einstein.Scraps {
public static class UserInput {
[DllImport("user32.dll", SetLastError=false)]
private static extern bool GetLastInputInfo(ref LASTINPUTINFO plii);
[StructLayout(LayoutKind.Sequential)]
private struct LASTINPUTINFO {
public uint cbSize;
public int dwTime;
}
public static DateTime LastInput {
get {
DateTime bootTime =
DateTime.UtcNow.AddMilliseconds(-Environment.TickCount);
DateTime lastInput =
bootTime.AddMilliseconds(LastInputTicks);
return lastInput;
}
}
public static TimeSpan IdleTime {
get {
return DateTime.UtcNow.Subtract(LastInput);
}
}
public static int LastInputTicks {
get {
LASTINPUTINFO lii = new LASTINPUTINFO();
lii.cbSize = (uint)Marshal.SizeOf(typeof(LASTINPUTINFO));
GetLastInputInfo(ref lii);
return lii.dwTime;
}
}
}
}
'@
for ( $i = 0; $i -lt 10; $i++ ) {
[Einstein.Scraps.UserInput]::LastInput.ToLocalTime()
Start-Sleep -Seconds 5}