Easiest way to reliably do it: hook into the LowLevelKeyboardHook and LowLevelMouseHook messages from your program. No matter which app has focus, your code will receive notifications that a key is being pressed or a mouse event occurs. Each time you receive the key or mouse message, reset the timer. If the timer ever expires, they haven't sent in any input for the duration of your timer, so you can assume they're not actively using it.
You can't do this in VBScript, but you can make a COM dll which you can call from VBScript. The following code MUST be in a .bas module though, which you can call from a COM class in the same dll...
Option Explicit
Private Const WH_KEYBOARD_LL = 13&
Private Const HC_ACTION = 0&
Private Type KBDLLHOOKSTRUCT
vkCode As Long
scanCode As Long
flags As Long
time As Long
dwExtraInfo As Long
End Type
Private m_hDllKbdHook As Long
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private 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
Private Declare Function UnhookWindowsHookEx Lib "user32" _
(ByVal hHook As Long) As Long
Private Declare Function CallNextHookEx Lib "user32" _
(ByVal hHook As Long, _
ByVal nCode As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" _
Alias "RtlMoveMemory" _
(pDest As Any, _
pSource As Any, _
ByVal cb As Long)
Public Function StartHook(frm As Form) As Boolean
If Not frm Is Nothing Then
'set and obtain the handle to the keyboard hook
m_hDllKbdHook = SetWindowsHookEx(WH_KEYBOARD_LL, _
AddressOf LowLevelKeyboardProc, _
App.hInstance, _
0&)
Set tgt = frm
End If
StartHook = m_hDllKbdHook <> 0
End Function
Public Function StopHook() As Boolean
If m_hDllKbdHook <> 0 Then
Call UnhookWindowsHookEx(m_hDllKbdHook)
End If
m_hDllKbdHook = 0
End Function
Public Function LowLevelKeyboardProc(ByVal nCode As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
Static kbdllhs As KBDLLHOOKSTRUCT
'On receipt of the HC_ACTION code,
'wParam and lParam contain information
'about a keyboard message, and lParam
'holds the pointer to a KBDLLHOOKSTRUCT
'structure.
Call CopyMemory(kbdllhs, ByVal lParam, Len(kbdllhs))
If nCode = HC_ACTION Then
' reset your timer here
Else
LowLevelKeyboardProc = CallNextHookEx(m_hDllKbdHook, _
nCode, _
wParam, _
lParam)
End If
End Function