I don't have Windows so I can't test that.
But looking into the MSDN documentation of these two API functions might be helpful here:
https://msdn.microsoft.com/de-de/librar ... s.85).aspx
The elapsed time is stored as a DWORD value. Therefore, the time will wrap around to zero if the system is run continuously for 49.7 days. To avoid this problem, use the GetTickCount64 function. Otherwise, check for an overflow condition when comparing times.
They shifted the value to use the full 32-bit DWORD range (the full negative value is the zero point). The API equivalent to ElapsedMiliseconds() is GetTickCount64() (I believe).
https://msdn.microsoft.com/en-us/librar ... s.85).aspx
The tick count when the last input event was received (see LASTINPUTINFO) is not guaranteed to be incremental. In some cases, the value might be less than the tick count of a prior event. For example, this can be caused by a timing gap between the raw input thread and the desktop thread or an event raised by SendInput, which supplies its own tick count.
This could explain your issue.
Probably, Windows throttles the input thread a bit if there is no input for longer time. That would cause bigger differences.
If you need it bit more accurate, you could try to compare between return values of GetLastInputInfo() instead of comparing it to the tick clock. As long as there is no change between calls, there was no input since that time.
Do your own time measuring to check the difference (like you do it to measure the runtime of the main loop). Everytime there is a difference between GetLastInputInfo() calls, reset the measuring (startTime = ElapsedMilliseconds()). If your own time measuring reaches 5000ms, then the user is idle.
Comparing clock values across different threads tends to be inaccurate.
Edit: I made my idea into code. But it is with a simulated API call, because I don't have Windows to use the real thing.
Code: Select all
OpenWindow(0,0,0,320,200,"test bla bla")
Global lastInputTimeStamp.q = ElapsedMilliseconds()
Procedure.q LastInputTime()
ProcedureReturn lastInputTimeStamp
EndProcedure
thisInputThing.q = 0
lastInputThing.q = LastInputTime()
startTimer.q = ElapsedMilliseconds()
Repeat
thisInputThing = LastInputTime()
If lastInputThing <> thisInputThing
;there was input, reset the timer
startTimer.q = ElapsedMilliseconds()
lastInputThing = thisInputThing
EndIf
Debug ElapsedMilliseconds() - startTimer
WaitWindowEvent(1)
If WindowMouseX(0) <> -1 And WindowMouseY(0) <> -1 And (WindowMouseX(0) <> lastWindowMouseX Or WindowMouseY(0) <> lastWindowMouseY)
lastInputTimeStamp = ElapsedMilliseconds() - Random(500000,100) ;make the time artifically inaccurate
lastWindowMouseX = WindowMouseX(0)
lastWindowMouseY = WindowMouseY(0)
EndIf
Until ElapsedMilliseconds() - startTimer >= 5000
Debug "Tadaaaa!!!"
__________________________________________________
URL tags added
06.03.2018
RSBasic