Dim TimeCount As LongPrivate Sub Form_KeyDown(KeyCode As Integer, Shift As Integer) TimeCount = 0 End SubPrivate Sub Form_Load() TimeCount = 0 Timer1.Interval = 100 Timer1.Enabled = True End SubPrivate Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) TimeCount = 0 End SubPrivate Sub Timer1_Timer() TimeCount = TimeCount + 1 If TimeCount > 50 * 60 Then '累计总数大于5分钟 Timer1.Enabled = False End End If End Sub
Private Declare Function GetCursorPos& Lib "user32" (lpPoint As PointAPI) Private Type PointAPI X As Long: Y As Long End Type'也可以通过API来检测位置进行 Private Function MouseOpr() As Boolean Static x0 As Long, y0 As Long Dim nMouse As PointAPI, i As Long, dl As Long
'检测鼠标 是否移动 Call GetCursorPos(nMouse) '获取当前鼠标位置 If x0 <> nMouse.X Or y0 <> nMouse.Y Then MouseOpr = True x0 = nMouse.X: y0 = nMouse.Y If MouseOpr Then Exit Function
Dim TimeCount As LongPrivate Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
TimeCount = 0
End SubPrivate Sub Form_Load()
TimeCount = 0
Timer1.Interval = 100
Timer1.Enabled = True
End SubPrivate Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
TimeCount = 0
End SubPrivate Sub Timer1_Timer()
TimeCount = TimeCount + 1
If TimeCount > 50 * 60 Then
'累计总数大于5分钟
Timer1.Enabled = False
End
End If
End Sub
Private Declare Function GetCursorPos& Lib "user32" (lpPoint As PointAPI)
Private Type PointAPI
X As Long: Y As Long
End Type'也可以通过API来检测位置进行
Private Function MouseOpr() As Boolean
Static x0 As Long, y0 As Long
Dim nMouse As PointAPI, i As Long, dl As Long
'检测鼠标 是否移动
Call GetCursorPos(nMouse) '获取当前鼠标位置 If x0 <> nMouse.X Or y0 <> nMouse.Y Then MouseOpr = True
x0 = nMouse.X: y0 = nMouse.Y If MouseOpr Then Exit Function
End Function
他的问题是“对当前程序无任何操作时”
这个“当前程序”包含的意思可就大了,可以是窗口,可以是一个线程或进程。
可以是一个后台运行的过程。还可以扩展到网络、系统消息、管道信息来看。
这个“无任何操作”可以是计算机与人的互动操作也可以是程序间的信息交互
操作或是程序的某个过程的执行情况。
这样下去即使是监视那个程序进程在CPU里的占用率也未必是正确的结果。因为
所以没有具体需求和范围,怎么说都可以是正确的或不正确的,这要看从哪个
角度去看这种问题。