本文介绍了AFK 2分钟并关闭表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
AFK 2分钟后如何自动关闭表单(无鼠标移动,无输入)
How can I auto close form after 2 minutes AFK (no mouse movement, no typing)
帮帮我
推荐答案
Imports System.Runtime.InteropServices
Public Class Form1
Private WithEvents Timer1 As New Timer With {.Interval = 1000, .Enabled = True}
Private LII As New LASTINPUTINFO() With {.cbSize = CUInt(Marshal.SizeOf(LII))}
Private WaitMinutes As Double = 2.0 'The time in minutes to wait after no user input is detected
<DllImport("user32.dll")> Private Shared Function GetLastInputInfo(ByRef plii As LASTINPUTINFO) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
<StructLayout(LayoutKind.Sequential)>
Private Structure LASTINPUTINFO
Public cbSize As UInteger
Public dwTime As UInteger
End Structure
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
GetLastInputInfo(LII)
Me.Text = CInt((Environment.TickCount - LII.dwTime) / 1000).ToString 'this line is just for testing, it can be removed
If CInt((Environment.TickCount - LII.dwTime) / 1000) >= (WaitMinutes * 60) Then
Timer1.Stop()
Timer1.Dispose()
Me.Close()
End If
End Sub
End Class
这篇关于AFK 2分钟并关闭表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!