Idle time
I am trying to have my program time out if the user lets it sit idle for an amount of time. Is there an easy way to find the last user input? I am useing VB.NET.
Thenks Mike
I am trying to have my program time out if the user lets it sit idle for an amount of time. Is there an easy way to find the last user input? I am useing VB.NET.
Thenks Mike
Public Class Form1 Private WarnIdle As Boolean = False Private LastTime As Date <System.Security.SuppressUnmanagedCodeSecurity(), System.Runtime.InteropServices.DllImport("kernel32.dll")> _ Public Shared Sub Sleep(ByVal dwMilliseconds As Long) End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load WarnIdle = True LastTime = Date.Now() AddHandler Application.Idle, AddressOf OnIdle End Sub Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing RemoveHandler Application.Idle, AddressOf OnIdle End Sub Private Sub Form1_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove LastTime = Date.Now End Sub Public Sub OnIdle(ByVal sender As Object, ByVal e As EventArgs) Do While Me.Created Dim thetime As TimeSpan = Date.Now() - LastTime If thetime.Seconds > 5 And WarnIdle Then MsgBox("You are Idle") LastTime = Date.Now End If Application.DoEvents() Sleep(100) Loop End Sub End Class |