0

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?

Josh-Mason
  • 319
  • 3
  • 8
  • 22
  • Capture screen image and compare – ElektroStudios Oct 17 '13 at 12:49
  • If you want to track activity on the given computer, you would have to take care of the running programs (not just video-related ones). Even by focusing just on videos, you would have to track the given programs: the player (e.g., WMP) on the computer or all the browsers and track its activity (to determine if a video is being played or not). – varocarbas Oct 17 '13 at 13:43
  • In reply to Elektro Hacker, Wouldn't this make the application unnecessarily slow? In reply to Varocarbas, So you're suggesting it couldn't be done in the way I intended? – Josh-Mason Oct 17 '13 at 13:55
  • If want you intend is finding a way to know if a video is being played at all, the answer is: it would be very difficult (or even impossible) without relying on the "intermediate unit" Windows uses for this kind of things: programs/applications/processes/services, etc. In any case, as said, you would have to take care of running processes anyway (this is the first thing to do when building an activity tracker) and, IMO, this is where you should focus your efforts (tracking running processes and knowing what they do, how you can affect them, etc.). – varocarbas Oct 17 '13 at 14:13
  • What about simply getting the time until windows will lock? – Josh-Mason Oct 17 '13 at 14:21
  • ?! I am not sure if we are talking even about the same reality. One thing is determining whether there is any activity at all on the given computer (user intervention + programs); another thing is knowing if the given session has been suspended or similar, a situation arbitrarily provoked by the user (or automatically by the OS); you might hook the suspension process to know about this before the suspension/locking actually happens (not sure on this front, you should do some research). In any case, from this conversation, it is pretty clear to me that you should do some research before asking. – varocarbas Oct 17 '13 at 14:30
  • ... you know: minimal understanding of the problem, attempted solutions, problem/solution useful for someone at all, etc. – varocarbas Oct 17 '13 at 14:31
  • PS: if you don't type @nick-person-you-are-talking, the other person might not be getting what you say (unless you are writing on his own question/answer). – varocarbas Oct 17 '13 at 14:33
  • I've done plenty of research and, as far as Google knows, nobody wants the same kind of function as me. I found out how to get keyboard and mouse activity first, but then thought of the problem with things such as video playback. – Josh-Mason Oct 17 '13 at 15:18
  • You are focusing your problem (and how to ask here) completely wrong. Please, refer to the two options above: if you want to track the user activity you are ignoring the most important source (running programs), you should do some research on this front/build a working code and ask specific questions here (you might restrict yourself to video-playing programs if you wish); there is nothing on these lines in your question. If you want to hook when the computer is locked/suspended this would be a different story (would have to redo your question), again I cannot see any effort on this front. – varocarbas Oct 17 '13 at 15:26
  • @varocarbas I'm sorry if I'm being a tad abrupt; I just seem to be getting nowhere with this. I need a few key words or another idea to give me a little boost in the right direction (rephrasing "How to get time until a computer locks vb.net" or "How to get active programmes in vb.net" and so on, just isn't returning anything new). – Josh-Mason Oct 17 '13 at 15:48
  • https://www.google.com/search?q=hook+windows+lock+vb.net&oq=hook+windows+lock+vb.net&aqs=chrome..69i57.6635j0j7&sourceid=chrome&espv=210&es_sm=93&ie=UTF-8#es_sm=93&espv=210&q=windows+inactivity+timeout+winapi+vb.net The first result gives you some hints to start to work with. This is how it works: you have to know something or do some work by your own. If you are not able to do so, you should stop considering SO, and try to hire a developer (unless to do this). – varocarbas Oct 17 '13 at 15:54

0 Answers0