// in the main form's OnShow event, add the following lines application.onmessage:= appMessage; fLastActivity:= GetTickCount64; timer2.enabled:= true; // here is appMessage procedure TMainForm.AppMessage (var msg: TMsg; var handled: boolean); var IdleBeforeReset: cardinal; msgname, s, formname: string; begin case msg.message of WM_LBUTTONDOWN: msgname:= 'WM_LBUTTONDOWN'; WM_RBUTTONDOWN: msgname:= 'WM_RBUTTONDOWN'; WM_MBUTTONDOWN: msgname:= 'WM_MBUTTONDOWN'; WM_MOUSEWHEEL: msgname:= 'WM_MOUSEWHEEL'; WM_KEYDOWN: msgname:= 'WM_KEYDOWN'; WM_SYSKEYDOWN: msgname:= 'WM_SYSKEYDOWN'; else msgname:= '-'; end; if msgname <> '-' then begin IdleBeforeReset:= (GetTickCount64 - fLastActivity) div 1000; if IdleBeforeReset > 60 then begin if screen.activeform <> nil then formname:= screen.activeform.Name else formname:= '<None>'; s:= format ('%s idle reset after %d seconds, message = %s, activeform = %s', [CompName, IdleBeforeReset, msgname, formname]); Write2Log (s); end; fLastActivity:= GetTickCount64; end; end;
This code is actually a hybrid of CoPilot's and mine. The first part means
that if one of the given events is detected, the variable
msgname gets a value. If the event was one of the tracked
events, then the code checks to see whether the time out period is about to
elapse (this check is made when more than one minute has passed, but looking
at this now, it would be far better if it were made when there there is less
than one minute remaining to the end of the time out period), and if so,
first discovers what the active form is, then writes data to a log file. I
intend to check this log file to see which events are happening to whom
close to the time out period in which form, and whether the time out
actually occurs (this is in the Timer2timer event handler).
I replaced the line
IdleBeforeReset > 60 which would have logged any activity after a break of a minute with this line
if IdleBeforeReset >= MaxTimeOutValue - 60 that logs only the event that prevented timing out at the last minute.
Much more useful.
It will be interesting to see what the log contains.
| Title | Tags | ||
|---|---|---|---|
| 1086 | Tom Paxton | Personal | |
| 1270 | Coincidence or deliberate reference? | John Le Carre, Non-fiction books | |
| 1544 | Extending cooking length for chicken | Cooking, Ninja grill | |
| 2029 | Implementing CP Prolog - 6 | Programming, Prolog, CoPilot |
No comments:
Post a Comment