Hi,

Hi all,

I am developing a software which computes the total time user worked. For this i have to check whether user is idle or away or whether user logged off the system etc. so can you please tell me how we can check whether user is idle or busy using c# code. Is there any api's

Thank you in Advance




Re: Visual C# General Idle,Away state in c#

Peter Ritchie

There's nothing specific to detect the user being "Idle" or "away". You could detect when a screen saver becomes active; otherwise, you'll have to define what "Idle" and "Away" is.






Re: Visual C# General Idle,Away state in c#

ChunSheng Tang - MSFT

Hi,

If I haven't misunderstood you, your quesion is (at least to some extent) equal to

How to tell if there is someone sitting in front of the computer and working with it

Does a computer have any feelings so that it can detect this The computer has no eyes(or ears, etc.), unless you are using a camera. However the computer can know that you 'touch' it when you press a key on the keyboard or click a mouse button.

One way I know to monitor keyboard/mouse actions is to use hooks. Once you've hooked these messages using SetWindowsHookEx API you can tell if the user is interacting with the computer by analyzing the intervals of these messages. If you use this method, take care of the hook procedure to reduce the overhead to the system performance.

Here is an sample of hooks:

Global System Hooks in .NET

Best Regards

Chunsheng Tang






Re: Visual C# General Idle,Away state in c#

Hi,

thank you for ur reply.

is there any functions in c# to find whether computer is locked or not






Re: Visual C# General Idle,Away state in c#

ChunSheng Tang - MSFT


There isn't AFAIK. You have to find some workarounds such as monitor the win+L(not quite reliable) or intercept some message generated when computer is locked if there is one.





Re: Visual C# General Idle,Away state in c#

Hi,

Is there any alternative methods or logic to achieve this(other than keyboard event and hook concept.






Re: Visual C# General Idle,Away state in c#

Peter Ritchie

As far as I know there's no way to "detect" if a worktation is locked. You can PInvoke WTSRegisterSessionNotification to be notified when a workstation is locked and unlocked. For "Idle", you'll have to define what the means: no mouse/keyboard for x minutes; or CPU usage has dropped to x%, etc...






Re: Visual C# General Idle,Away state in c#

Hi,

Locking problem is solved. Thank you very much for your replies. Now i am facing with new problem.

How i can get active or current focused process or application when user switches between different application. Any windows message is there for this .

First i used WM_ACTIVATEAPP. But this works when i switch between the my application(which has ACTIVATEAPP) and other application. But if i am switching between other than my application this doesnt work. can u please tell how can i resolve this