I have found this way, which detects when the screensaver starts and stops:
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
Const WM_SYSCOMMAND As Integer = &H112
Const SC_SCREENSAVE As Integer = &HF140
MyBase.WndProc(m)
If m.Msg = WM_SYSCOMMAND AndAlso m.WParam.ToInt32 = SC_SCREENSAVE Then
MsgBox("Capturado screensaver" & Now.ToLongTimeString)
AddHandler Application.Idle, AddressOf Application_Idle
End If
End Sub
Private Sub Application_Idle(ByVal sender As Object, ByVal e As EventArgs)
MsgBox("Capturada actividade" & Now.ToLongTimeString)
RemoveHandler Application.Idle, AddressOf Application_Idle
End Sub
Basically what I did was to detect the screensaver activation and at that time I create a handler for the Idle
event so, when i get user activity (which is what stops the screensaver) I know when the screensaver stopped.