WPF 检测输入状态

时间:2021-12-05 09:59:10
        [DllImport("user32.dll")]
static extern bool GetLastInputInfo(ref LASTINPUTINFO plii); public static long GetIdleTick()
{
LASTINPUTINFO lastInputInfo = new LASTINPUTINFO();
lastInputInfo.cbSize = Marshal.SizeOf(lastInputInfo);
if (!GetLastInputInfo(ref lastInputInfo)) return ;
return Environment.TickCount - (long)lastInputInfo.dwTime;
} [StructLayout(LayoutKind.Sequential)]
private struct LASTINPUTINFO
{
[MarshalAs(UnmanagedType.U4)]
public int cbSize;
[MarshalAs(UnmanagedType.U4)]
public uint dwTime;
}