Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting idle users in Winforms

Tags:

c#

winforms

I'd like to pause my program if a user is inactive for 5 minutes. By inactive I mean hasn't pressed their mouse or their keyboard during that time (including outside the program too!). Any starting points?

like image 449
Andrew Avatar asked Jun 08 '11 16:06

Andrew


4 Answers

Within a timer you could p/invoke GetLastInputInfo() which will return the number ms since input was detected from the user, across all processes in the current session.

like image 153
Alex K. Avatar answered Nov 17 '22 06:11

Alex K.


This question is very similar to an old question:

.NET equivalent for GetLastInputInfo?

Which referenced a good article describing some different options in C#:

http://www.codeproject.com/KB/cs/uim.aspx

If you don't mind using P/Invoke and being limited to running on windows systems, then using P/Invoke to call GetLastInputInfo() is probably the simplest method of accomplishing what you want.

like image 29
dschaeffer Avatar answered Nov 17 '22 05:11

dschaeffer


you could override the WndProc and look for the WM_IDLE message

like image 2
Matthew Sanford Avatar answered Nov 17 '22 05:11

Matthew Sanford


I've used the GMA.UserActivityMonitor library a while ago to achieve this.

like image 2
DanielB Avatar answered Nov 17 '22 05:11

DanielB