feat(watcher): add GetLastInputInfo P/Invoke for idle detection
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -13,4 +13,22 @@ internal static partial class NativeMethods
|
|||||||
|
|
||||||
[LibraryImport("user32.dll", SetLastError = true)]
|
[LibraryImport("user32.dll", SetLastError = true)]
|
||||||
internal static partial uint GetWindowThreadProcessId(IntPtr hWnd, out uint processId);
|
internal static partial uint GetWindowThreadProcessId(IntPtr hWnd, out uint processId);
|
||||||
|
|
||||||
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
|
internal struct LASTINPUTINFO
|
||||||
|
{
|
||||||
|
public uint cbSize;
|
||||||
|
public uint dwTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
[DllImport("user32.dll")]
|
||||||
|
internal static extern bool GetLastInputInfo(ref LASTINPUTINFO plii);
|
||||||
|
|
||||||
|
internal static TimeSpan GetIdleTime()
|
||||||
|
{
|
||||||
|
var info = new LASTINPUTINFO { cbSize = (uint)Marshal.SizeOf<LASTINPUTINFO>() };
|
||||||
|
if (!GetLastInputInfo(ref info))
|
||||||
|
return TimeSpan.Zero;
|
||||||
|
return TimeSpan.FromMilliseconds(Environment.TickCount64 - info.dwTime);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user