Andrew
Andrew

Reputation: 2539

Detecting idle users in 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?

Upvotes: 14

Views: 10293

Answers (5)

only_one
only_one

Reputation: 552

Looks like I found solution for Your problem, look at:

How to detect a Winforms app has been idle for certain amount of time and user34660 answer,

For your app, must change:

const int MinuteMicroseconds = 60000;

to

const int MinuteMicroseconds = 300000;

It's just time, but in ms.

Works nice for my Windows Forms application.

Upvotes: 0

dschaeffer
dschaeffer

Reputation: 618

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.

Upvotes: 6

Alex K.
Alex K.

Reputation: 175846

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.

Upvotes: 11

DanielB
DanielB

Reputation: 20240

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

Upvotes: 2

Matthew Sanford
Matthew Sanford

Reputation: 1099

you could override the WndProc and look for the WM_IDLE message

Upvotes: 2

Related Questions