Is there a way to check if the user is currently on?

There is documentation on the Internet that shows that Windows changes the behavior of the NotifyIcon.BalloonTipShown command if the user is currently not working, and this is detected by checking keyboard and mouse events . I am currently working on an application that spends most of the time in the system tray, but from time to time several tooltips with balls pop up, and I would like the user not to miss any of them if they are currently away from the system . Since any balloon prompts currently displayed are destroyed if a new one is displayed, I want them to be displayed if the user is not working.

As such, is there a way to check if the user is currently running if the application is minimized to the system tray?

+3
source share
3 answers

What about the Win32 LASTINPUTINFO function ?

using System.Runtime.InteropServices;

[DllImport("User32.dll")] 
static extern bool GetLastInputInfo(ref LASTINPUTINFO plii);

struct LASTINPUTINFO 
{
    public uint cbSize;
    public uint dwTime;
}
+4
source

Managed code

Check your mouse position every second. If there are new messages for the user, hold on to them until you detect any movement with the mouse.

Unmanaged code

See Detecting downtime using mice and keyboard hooks.

+1
source

Thanks for the answers, I ended up working with the GetLastInputInfo function, since it is quite simple to implement in the application I'm working on.

0
source

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


All Articles