1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| Private Type LASTINPUTINFO
cbSize As Long
dwTime As Long
End Type
Private quand As Double, interval As Integer, duree As Long
Private Sub Form_Initialize()
Dim monintervalle As Integer
monintervalle = 3 ' pour un intervalle de 3 secondes entre chaque vérif du timer
duree = 100 ' on définit ici la durée (en secondes) d'inactivité au delà le laquelle on intervient
TimerOn monintervalle
End Sub
Public Function inactif(ByVal duree As Long) As Boolean
Dim deract As LASTINPUTINFO
deract.cbSize = Len(deract)
If GetLastInputInfo(deract) <> 0 Then
inactif = (GetTickCount - deract.dwTime) > (1000 * duree)
End If
End Function
'=====================================================================================
'je n'ai pas Excel sous la main pour pouvoir vérifier ce qui suit (substitut d'un Timer)
' j'écris donc à main levée
' corrige au besoin (devrait pas y avoir beaucoup à corriger)
Sub TimerOn(intv As Integer)
interval = intv
Application.OnTime Now + TimeSerial(0, 0, interval), "LeTimer"
End Sub
Sub TimerOff()
On Error Resume Next
Application.OnTime quand, "LeTimer", , False
End Sub
Sub LeTimer()
If inactif(duree) Then
TimerOff
MsgBox "durée d'inactivité dépassée"
' remplace ici le msgbox par tes instructions à toi (de fermeture, donc)
Exit Sub
End If
Lheure = Now + TimeSerial(0, 0, interval)
Application.OnTime quand, "LeTimer"
End Sub |