title: VB Detect Idle time
body: <p>I'm looking for a way to detect if the user has been idle for 5 min then do something, and if and when he comes back that thing will stop, for example a timer.</p>
  
  <p>This is what i have tried (but this will only detect if form1 has been inactive / not clicked or anything):</p>
  
  <pre><code>Public Class Form1
  
  Private Sub form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
      'You should have already set the interval in the designer... 
      Timer1.Start()
  End Sub
  
  Private Sub form1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
      Timer1.Stop()
      Timer1.Start()
  End Sub
  
  
  Private Sub form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
      Timer1.Stop()
      Timer1.Start()
  End Sub
  
  Private Sub form1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseClick
      Timer1.Stop()
      Timer1.Start()
  End Sub
  
  Private Sub Timer_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
      MsgBox("Been idle for to long") 'I just have the program exiting, though you could have it do whatever you want.
  End Sub
  
  End Class
  </code></pre>