ReactOS 0.4.16-dev-2354-g16de117
UserIdleTime.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Tests
3 * LICENSE: MIT (https://spdx.org/licenses/MIT)
4 * PURPOSE: Calculate and print user idle time once per second by using
5 * user32!GetLastInputInfo() API and SharedUserData->LastSystemRITEventTickCount
6 * field separately. The former updates in real-time, while the latter updates
7 * periodically (60s in NT5, 1s since NT6.0). Press Ctrl+C to exit this program.
8 * COPYRIGHT: Copyright 2026 Ratin Gao <ratin@knsoft.org>
9 */
10
11#include <stdio.h>
12
13#define WIN32_NO_STATUS
14#include <windef.h>
15#include <winbase.h>
16#include <winuser.h>
17
18#define NTOS_MODE_USER
19#include <ndk/psfuncs.h>
20
21int
22_cdecl
24 _In_ int argc,
25 _In_reads_(argc) _Pre_z_ wchar_t** argv)
26{
27 DWORD dwTickCount, dwError;
28 LASTINPUTINFO lii = { sizeof(lii) };
29
30 puts("User idle time in second (LastSystemRITEventTickCount, GetLastInputInfo):");
31 for (;;)
32 {
33 dwTickCount = GetTickCount();
34 if (!GetLastInputInfo(&lii))
35 {
36 dwError = GetLastError();
37 printf("GetLastInputInfo failed with: 0x%08lX\n", dwError);
38 return dwError;
39 }
40 printf("\t%lu, %lu\n",
41 (dwTickCount - SharedUserData->LastSystemRITEventTickCount) / 1000UL,
42 (dwTickCount - lii.dwTime) / 1000UL);
43 Sleep(1000);
44 }
45
46 return 0;
47}
int puts(const char *string)
Definition: crtsupp.c:23
ULONG WINAPI DECLSPEC_HOTPATCH GetTickCount(void)
Definition: sync.c:182
MonoAssembly int argc
Definition: metahost.c:107
unsigned long DWORD
Definition: ntddk_ex.h:95
#define printf
Definition: freeldr.h:104
#define argv
Definition: mplay32.c:18
#define _In_reads_(s)
Definition: no_sal2.h:168
#define _In_
Definition: no_sal2.h:158
#define _Pre_z_
Definition: no_sal2.h:506
int wmain()
#define SharedUserData
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:726
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
BOOL WINAPI GetLastInputInfo(_Out_ PLASTINPUTINFO)