Inaction user discovery (for each application instance)

I need a definition of user inactivity only in my application (for the "instance of my application").
I cannot use GetLastInputInfo because user input for the session :

GetLastInputInfo does not provide system-wide user input in all sessions. Rather, GetLastInputInfo provides user login information for the user only for the session that called the function.

Any suggestions?

+4
source share
3 answers

You can use Application.AddMessageFilter and watch messages representing user interaction (e.g. mouse, keyboard, possibly menu activation).

+4
source

I assume that you want to determine downtime, but only with an active application. Then you need to determine exactly what you mean by your application. When your application is active (by its own definition), you can call GetLastInputInfo at regular intervals to determine the downtime of your application when it is active (for example, using a timer of some type).

Windows has the concept of a foreground window, and the current foreground window can be retrieved using GetForegroundWindow . You can use GetWindowThreadProcessId to find the process ID of the process to which the foreground window belongs. If this process identifier is the identifier of your process, you know that you are the main process, even if your application has several windows. You will have to do this detection at regular intervals, just as you should check the downtime.

You should not worry about GetLastInputInfo by providing only session information. If several users log on to the same Windows computer, each of them will have their own session, but the other user, who is in standby mode or not working in the session, should not affect the way you find that your user the application is idle.

+5
source

If it is a Windows Forms application, you can create an inactivity event handler and subscribe to the Application.Idle event. You will receive a notification when the application finishes processing and is about to enter the standby state.

+2
source

Source: https://habr.com/ru/post/1339826/


All Articles