views:

207

answers:

3

In a Win32 environment, you can use the GetLastInputInfo API call see msdn doc. Basically, this method returns the last tick that corresponds with when the user last provided input, and you have to compare that to the current tick to determine how long ago that was.

Xavi23cr has a good example for C# at codeproject.

Any suggestions for other environments?

+1  A: 

As for Linux, I know that Pidgin has to determine idle time to change your status to away after a certain amount of time. You might open the source and see if you can find the code that does what you need it to do.

superjoe30
+1  A: 

You seem to have answered your own question there Nathan ;-) "GetLastInputInfo" is the way to go.

One trick is that if your application is running on the desktop, and the user connects to a virtual machine, then GetLastInputInfo will report no activity (since there is no activity on the host machine).

This can be different to the behaviour you want, depending on how you wish to apply the user input.

Leon Bambrick
He's looking for suggestions in environments other than Windows.
indyK1ng
A: 

This blog post has various solutions for Cocoa.

Sören Kuklau