AFK 2分钟并关闭表格

编程入门 行业动态 更新时间:2024-10-22 15:37:08
本文介绍了AFK 2分钟并关闭表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

大家好,

AFK 2分钟后如何自动关闭表单(无鼠标移动,无输入)

How can I auto close form after 2 minutes AFK (no mouse movement, no typing)

帮帮我

推荐答案

您可以使用GetLastInputInfo win32 Api来检测键盘和鼠标上没有用户输入在给定的时间内.下面是一个可以在新表单项目中尝试的示例.

You can use the GetLastInputInfo win32 Api to detect no user input on the keyboard and mouse for a given amount of time. Below is an example that you can try in a new form project. 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分钟并关闭表格

本文发布于:2023-11-27 04:18:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1636563.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:表格   AFK

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!