<p>In a <strong>Win32</strong> environment, you can use the <strong>GetLastInputInfo API</strong> call in <a href="https://learn.microsoft.com/windows/desktop/api/winuser/nf-winuser-getlastinputinfo" rel="nofollow noreferrer">Microsoft documentation</a>.  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.</p>

<p>Xavi23cr has a good example for C# at <a href="http://www.codeproject.com/KB/cs/GetIdleTimeWithCS.aspx" rel="nofollow noreferrer">codeproject</a>.</p>

<p>Any suggestions for other environments?</p>

[{'answer_id': 2720, 'author': 'andrewrk', 'author_id': 432, 'author_profile': 'https://Stackoverflow.com/users/432', 'pm_score': 2, 'selected': False, 'text': '<p>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.</p>\n'}, {'answer_id': 3013, 'author': 'Leon Bambrick', 'author_id': 49, 'author_profile': 'https://Stackoverflow.com/users/49', 'pm_score': 1, 'selected': False, 'text': '<p>You seem to have answered your own question there Nathan ;-)\n"GetLastInputInfo" is the way to go.</p>\n\n<p>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).</p>\n\n<p>This can be different to the behaviour you want, depending on how you wish to apply the user input.</p>\n'}]
['https://Stackoverflow.com/questions/2709', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/434/']