title: Cross platform keylogger
body: <p>I'm looking for ways to watch mouse and keyboard events on Windows, Linux and Mac from Python.</p>
  
  <p>My application is a time tracker. I'm not looking into the event, I just record the time when it happens. If there are no events for a certain time, say 10 minutes, I assume that the user has left and stop the current project.</p>
  
  <p>When the user returns (events come in again), I wait a moment (so this doesn't get triggered by the cleaning crew or your pets or an earthquake). If the events persist over a longer period of time, I assume that the user has returned and I pop up a small, inactive window where she can choose to add the time interval to "break", the current project (meeting, etc) or a different project.</p>
  
  <p>I've solved the keylogger for Windows using the <a href="http://sourceforge.net/projects/pyhook/" rel="noreferrer">pyHook</a>.</p>
  
  <p>On Linux, I have found a solution but I don't like it: I can watch all device nodes in /etc/input and update a timestamp somewhere in /var or /tmp every time I see an event. There are two drawbacks: 1. I can't tell whether the event if from the user who is running the time tracker and 2. this little program needs to be run as root (not good).</p>
  
  <p>On Mac, I have no idea, yet.</p>
  
  <p>Questions:</p>
  
  <ol>
  <li><p>Is there a better way to know whether the user is creating events than watching the event devices on Linux?</p></li>
  <li><p>Any pointers how to do that on a Mac?</p></li>
  </ol>