Advertisement
Guest User

Untitled

a guest
Mar 6th, 2022
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Imports System.Runtime.InteropServices
  2. Public Class Form1
  3.     <DllImport("user32.dll")> Private Shared Function GetLastInputInfo(ByRef plii As LASTINPUTINFO) As Boolean
  4.     End Function
  5.  
  6.     <StructLayout(LayoutKind.Sequential)>
  7.     Structure LASTINPUTINFO
  8.         Public cbSize As UInteger
  9.         Public dwTime As Integer
  10.     End Structure
  11.     Dim lastInput = New LASTINPUTINFO()
  12.     Dim alreadyWarned As Boolean = False
  13.     Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  14.         lastInput.cbSize = Marshal.SizeOf(lastInput)
  15.         lastInput.dwTime = 0
  16.     End Sub
  17.  
  18.     Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
  19.  
  20.         GetLastInputInfo(lastInput)
  21.  
  22.         If ((Environment.TickCount - lastInput.dwTime) / 60000) >= 30 Then '>= 30 minutes
  23.            If Not alreadyWarned Then
  24.                 alreadyWarned = True 'Do this so we don't spam a message box every second
  25.                MsgBox("You've been idle for a while")
  26.             End If
  27.         Else
  28.             alreadyWarned = False 'Reset if the system is no longer idle
  29.        End If
  30.  
  31.     End Sub
  32. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement