views:

49

answers:

1

Is there a neat/easy way in objective-c/cocoa to track if a user is at their computer, ie I assume by detecting key presses and mouse movement?

(ie I want to fill out my timesheet automatically by detecting when I am at work and not at work)

+1  A: 

You can detect mouse events across the entire log-in session using an event tap.

I'm pretty sure there's a way to do this for key events as well, but I don't remember what it was and it requires that the user have access for assistive devices turned on. Catching key events across the session is hard on purpose, in order to make Mac OS X unattractive for key-logger authors.

You should also use NSWorkspace's notifications to detect when the machine is about to go to sleep, and when it has just woken up from sleep.

Peter Hosey
Doh! I can go 30 minutes or longer without having to touch the mouse (in fact if I am doing server tasks I probably don't touch the mouse for an hour or more)
Jacob