I've used this solution to the very same problem. It's code I found on the net, but I've adapted it to my needs.
You should be able to drop this into your code window and modify it as needed.
Public Structure LASTINPUTINFO
Public cbSize As Int32
Public dwTime As Int32
End Structure
Declare Function GetLastInputInfo Lib "User32.dll" (ByRef plii As LASTINPUTINFO) As Boolean
Private Sub IdleTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles IdleTimer.Tick
If ReportingEntireClass = False Then
Dim LII As New LASTINPUTINFO, TicksSinceLastInput As Int32 = 0
LII.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(LII)
If GetLastInputInfo(LII) Then TicksSinceLastInput = (Environment.TickCount - LII.dwTime)
If TicksSinceLastInput >= IdleSeconds Then
If IdleClosing = False Then
IdleClosing = True
Idle.ShowDialog() 'this is a little
'form that warns about the app closing.
End If
End If
End If
End Sub