VB判断1分钟没有鼠标和键盘触发软件界面,然后关闭程式

2024-12-02 17:06:04
推荐回答(2个)
回答1:

’f是标致,有键盘或鼠标按下就为假
’60秒后如果f为真,说明没有按下,因此退出。
Option Explicit
Dim f As Boolean

Private Sub Form_Click()
f = False
End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
f = False
End Sub

Private Sub Form_Load()
Timer1.Enable = True
Timer1.Interval = 1000
f = True
End Sub

Private Sub Timer1_Timer()
Static c As Integer
c = c + 1
If c >= 60 And f = True Then
End
End If
End Sub

回答2:

简单一点的方法,用time控件检测mouse api