kurt minds
вы можете использовать этот код, просто преобразуя его в c#.
Option Strict On
Imports System.Runtime.InteropServices
Public Class IdleTime
Public Structure LASTINPUTINFO
Public cbSize As UInteger
Public dwTime As UInteger
End Structure
'API call that let us detect any keyboard and/or mouse activity
<DllImport("user32.dll")> _
Private Shared Function GetLastInputInfo(ByRef plii As LASTINPUTINFO) As Boolean
End Function
'Returns the time since last user activity
Public Function GetInactiveTime() As Nullable(Of TimeSpan)
Dim info As LASTINPUTINFO = New LASTINPUTINFO
info.cbSize = CUInt(Marshal.SizeOf(info))
If (GetLastInputInfo(info)) Then
Return TimeSpan.FromMilliseconds(Environment.TickCount - info.dwTime)
Else
Return Nothing
End If
End Function
End Class
На вашем MainModule добавьте эти коды
Private IdleTimer As IdleTime
Form_Load
'check autolock time / 10 minutes default
AutoLockTime = 600
If AutoLockTime <= 0 Then
InactivityTimer.Enabled = False 'Disabled
Else
AutoLockTime = AutoLockTime + 10 'Plus 10 Seconds Allowance
InactivityTimer.Enabled = True 'Activate Checking of Idle
End If
Добавить таймер и текст контрольной
Private Sub InactivityTimer_Tick(sender As System.Object, e As System.EventArgs) Handles InactivityTimer.Tick
Application.DoEvents()
If IS_BUSY_PROCESSING Then Exit Sub
'Calculates for how long we have been idle
Dim inactiveTime = IdleTimer.GetInactiveTime
If (inactiveTime Is Nothing) Or (AutoLockTime <= 0) Then
InactivityTimer.Enabled = False
ElseIf (inactiveTime.Value.TotalSeconds > 10) Then
Dim DisplayMinutes As Integer = (AutoLockTime - 10) / 60
Dim DisplayTime As Integer = AutoLockTime - (inactiveTime.Value.TotalSeconds)
Text1.Text = String.Format("Idle in {0} minute/s, the system will automatically lock. {1} time remaining.", DisplayMinutes, SecondsToHours(DisplayTime)))
If inactiveTime.Value.TotalSeconds >= AutoLockTime Then
'perform screen lock
PerformLockScreen()
End If
Else
'StatusBarMessage()
End If
End Sub
надеюсь, это поможет! :)