title: Check whether user is inactive
body: <p>How do I check user is inactive?
  I have this:</p>
  
  <pre><code>class UserActivity : IMessageFilter
  {
      private double afk_time = 0.1;//minutes
      private DateTime last_activity = DateTime.Now;
      public static bool inactive = false;
  
      private int WM_LBUTTONDOWN = 0x0201;
      private int WM_MBUTTONDOWN = 0x0207;
      private int WM_RBUTTONDOWN = 0x0204;
      private int WM_MOUSEWHEEL = 0x020A;
      private int WM_MOUSEMOVE = 0x0200;
      private int WM_KEYDOWN = 0x0100;
  
      public bool PreFilterMessage(ref Message m)
      {
          if (m.Msg == WM_LBUTTONDOWN || m.Msg == WM_MBUTTONDOWN || m.Msg == WM_RBUTTONDOWN || m.Msg == WM_MOUSEWHEEL || m.Msg == WM_MOUSEMOVE || m.Msg == WM_KEYDOWN)
          {
              this.last_activity = DateTime.Now;
              inactive = false;
          }
  
          if (DateTime.Now.AddMinutes(-afk_time) &gt; last_activity)
              inactive = true;
  
          return false;
      }
  }
  </code></pre>
  
  <p>But I must run it in Program.cs</p>
  
  <pre><code>Application.AddMessageFilter(new UserActivity());
  </code></pre>
  
  <p>How can I do that I can run the checking of user inactivity by my self. I'll check some checkbox and it will start checking.</p>
  
  <p>And I want check global user activity - in all system not only in app.</p>
  
  <p>I don't want use of cpu unnecessary. Or should I use another solution?</p>