I have a very simple application with a form, a richedit and a menu. I’m trying to automatically save the text on the richedit and perform other tasks but only when the application is idle – when the user is not writing or the app loses focus or whatever.
I tried creating an OnIdle event handler from a gazillion sample codes found on the internet, but it does the opposite, it activates when I am using the app. This link is an example.
I also tred with a timer and check when was the last time the user wrote to the richedit, but I rather not use a timer if possible.
Anyone knows how to detect that an application is idle and run some code when it is? I’m using delphi 7.
I would recommend an timer also, but would “reset” the countdown (toggle off and then back on) in response to any keyboard event occurring within the richedit. That way, you aren’t saving while the user is trying to type.
As Andreas pointed out, here’s how to actually implement this:
Every time the user performs some action, e.g. changes the caret pos of the editor, do Timer1.Enabled := false; Timer1.Enabled := true. This will reset the timer. In effect, the timer will never fire until there has been no user activity for the last Timer1.Interval milliseconds