views:

272

answers:

3

There is some documentation on the internet that shows that Windows changes the behavior of the NotifyIcon.BalloonTipShown command if the user is currently idle and this is detected by checking for keyboard and mouse events. I am currently working on an application that spends most of its time in the system tray, but pop-ups up multiple balloon tips from time to time and I would like to prevent the user from missing any of them if they are currently away from the system. Since any currently displayed balloon tips are destroyed if a new one is displayed, I want to hold off on displaying them if the user is away.

As such, is there any way to check to see if the user is currently idle if the application is minimized to the system tray?

+1  A: 

Managed code

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

Unmanaged code

See Detecting Idle Time with Mouse and Keyboard Hooks

lubos hasko
what about keyboard input?
Garrett
+4  A: 

How 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;
}
Mark Cidade
Right !!!I would just add link to the LASTINPUTINFO with LayoutKind.Sequential:http://www.pinvoke.net/default.aspx/Structures/LASTINPUTINFO.html
modosansreves
A: 

Thanks for the responses, I ended up going with the GetLastInputInfo function as it is pretty straight forward to implement in the application I'm working on.

Rob