How can you tell when the user last pressed a key (or moved the mouse)?

In a Win32 environment, you can use the GetLastInputInfo API see the msdn file . Basically, this method returns the last tick, which corresponds to when the user last entered the input, and you should compare it with the current tick to determine how long it was.

Xavi23cr has a good example for C # in codeproject .

Any suggestions for other environments?

+6
language-agnostic
source share
2 answers

As for Linux, I know that Pidgin has to determine the downtime in order to change its status for a while after a certain amount of time. You can open the source and see if you can find the code that does what you need.

+3
source share

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

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

This may differ from the behavior you want, depending on how you want to apply user input.

+1
source share

All Articles