My application is supposed to give a warning before a pc locks. It uses a timer, set to x seconds (x = time before the computer locks with inactivity). I use the following code to detect mouse and keyboard activity:
Private Declare Function GetLastInputInfo Lib "user32.dll" (ByRef inputStructure As inputInfo) As Boolean
Private Structure inputInfo
Dim structSize As Int32
Dim tickCount As Int32
End Structure
Private info As inputInfo
Dim lastTick As Int32
Dim firsttick As Int32
Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
'The size of the structure for the API call.
info.structSize = Len(info)
'
'Call the API.
GetLastInputInfo(info)
'
'Compare the tickcount values to determine if activity has occurred or not.
If firstTick <> info.tickCount Then
firsttick = info.tickCount
count = 15
Me.WindowState = FormWindowState.Minimized
Me.Visible = False
End If
End Sub
count is determined by timer 1 which has an interval of a second. If the user interacts with the keyboard or mouse, count is reset to x seconds (In this example, it's 15 seconds for testing purposes; I can't be bothered to wait the actual time every time I want to test the application). All of the above worked perfectly, until, that is, I thought about video playback. Incase you haven't noticed, playing a video on YouTube or WMP...etc prevents the PC from locking/sleeping.
My question is simple...How do I detect whether a video is playing and reset count back to x. An even better question is: How can I detect how long until the computer locks, so I wouldn't even need to have count or detect user activity?