Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Using GetLastInputInfo with user inactivity

$
0
0
I am having an issue here. I am still learning to code in vb.net, although I have come a long way since I started. I am having problems figuring out how to properly use the GetLastInputInfo code in a timer. I get the whole calling the API function and found this code to do it:
Imports System.Runtime.InteropServices
 
Public Class IdleTime
 
    Private Declare Function GetLastInputInfo Lib "User32.dll" _
      (ByRef lastInput As LASTINPUTINFO) As Boolean
 
    <structlayout(layoutkind.sequential)> _
    Public Structure LASTINPUTINFO
        Public cbSize As Int32
        Public dwTime As Int32
    End Structure
 

    Public ReadOnly Property IdleTime() As Integer
 
        Get
 
            Dim lastInput As New LASTINPUTINFO
 
            lastInput.cbSize = Marshal.SizeOf(lastInput)
 
            If GetLastInputInfo(lastInput) Then
 
                Return (Environment.TickCount - lastInput.dwTime) / 1000
 
            End If
 
        End Get
 
    End Property
 
End Class



My question is how do I now use this integer of time. For example, if 60 seconds has passed since last user input, I want to close a form and return to the first form. My current setup uses Wndproc and it is just too buggy for me to continue to use so I would like to switch over to GetLastInputInfo. Any help would be appreciated, hopefully this is something easy I am missing here.

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>