thank you anyway, but I've already solved the problem. Here is the code
'''''''''''''''''''
Option Explicit
Public Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal
nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Public Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal
nIDEvent As Long) As Long
Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA"
(ByVal idHook As Long, _
ByVal lpfn As Long, ByVal hMod As Long, _
ByVal dwThreadId As Long) As Long
Declare Function CallNextHookEx Lib "user32" (ByVal hhk As Long, _
ByVal nCode As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hhk As Long) As
Boolean
' BOOL= BOOLEAN ?
'''''''''' monitor for ellapse idle time
Private Const idleclick As Integer = 1000 ' in ms
Private mtickperiod As Integer
Private idlecountermax As Integer
Private idlecounter As Integer
Private TimerId As Long
Private mhookid As Long ' for mouse
Private khookid As Long ' for keyboard
Public ToNotifys As Collection 'for use only in idlenotify class
Private Function MouseProc(ByVal nCode As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
If nCode < 0 Then
MouseProc = CallNextHookEx(mhookid, nCode, wParam, lParam)
Else
idlecounter = 0
MouseProc = CallNextHookEx(mhookid, nCode, wParam, lParam)
End If
End Function
Private Function KeyProc(ByVal nCode As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
If nCode < 0 Then
KeyProc = CallNextHookEx(khookid, nCode, wParam, lParam)
Else
idlecounter = 0
KeyProc = CallNextHookEx(khookid, nCode, wParam, lParam)
End If
End Function
Private Sub TimerProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal idEvent
As Long, ByVal lngSysTime As Long)
Dim tmp As IdleNotifer
If idEvent = TimerId And idlecounter < idlecountermax Then
idlecounter = idlecounter + 1
If idlecounter = idlecountermax Then
'frm.WindowState = vbMinimized
For Each tmp In ToNotifys
tmp.RaiseIdle
Next
Else
For Each tmp In ToNotifys
tmp.RaiseTick idlecounter, idlecountermax - idlecounter
Next
End If
End If
End Sub
Public Sub RestartIdleMonitor()
Debug.Assert TimerId <> 0
idlecounter = 0
End Sub
Public Sub EndIdleMonitor() 'must call this before program end
If TimerId <> 0 Then
KillTimer 0, TimerId
TimerId = 0
End If
Set ToNotifys = Nothing
If mhookid <> 0 Then UnhookWindowsHookEx mhookid
mhookid = 0
If khookid <> 0 Then UnhookWindowsHookEx khookid
khookid = 0
End Sub
Public Function StartIdleMonitor(ltickperiod As Integer, ltickcount As
Integer) As Boolean
'WH_MOUSE 7
If mhookid = 0 Then _
mhookid = SetWindowsHookEx(7, AddressOf MouseProc, 0, App.ThreadID)
'WH_KEYBOARD 2
If khookid = 0 Then _
khookid = SetWindowsHookEx(2, AddressOf KeyProc, 0, App.ThreadID)
If TimerId <> 0 Then
KillTimer 0, TimerId
TimerId = 0
End If
idlecountermax = ltickcount
If idlecountermax < 2 Then idlecountermax = 2
idlecounter = 0
If ltickperiod < idleclick Then
mtickperiod = idleclick
Else
mtickperiod = ltickperiod
End If
If mhookid <> 0 And khookid <> 0 Then
TimerId = SetTimer(0, 0, mtickperiod, AddressOf TimerProc)
If TimerId <> 0 Then
StartIdleMonitor = True
Exit Function
End If
End If
EndIdleMonitor
StartIdleMonitor = False
End Function
Public Function tickperiod() As Integer
tickperiod = mtickperiod
End Function
Public Function TickCount() As Integer
TickCount = idlecountermax
End Function
''''''''''''''''''''''''''''''''''''''''
Option Explicit
Public Event IdleNotify()
' If you do not need this, comment out it
Public Event TickNotify(ByVal curTick As Integer, ByVal remainTick As
Integer)
Private index As Integer
Friend Sub RaiseTick(ByVal curTick As Integer, ByVal remainTick As Integer)
RaiseEvent TickNotify(curTick, remainTick)
End Sub
Friend Sub RaiseIdle()
RaiseEvent IdleNotify
End Sub
' call this before set nothing
Public Sub EndNotify()
ToNotifys.Remove "H" + Hex(index)
End Sub
Private Sub Class_Initialize()
If ToNotifys Is Nothing Then
Set ToNotifys = New Collection
End If
index = ToNotifys.Count
ToNotifys.Add Me, "H" + Hex(index)
End Sub