Uploaded February 2018 | Updated September 2026, 1 week ago
Steps to detect when PC goes to sleep and wakes up in VB.NET.
.Net Framework 4.6.1
Windows Forms App
Visual Studio Community
Windows 10
#vbdotnet
----------------------
Imports Microsoft.Win32
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
AddHandler SystemEvents.PowerModeChanged, AddressOf SystemEvents_PowerModeChanged
End Sub
Private Sub SystemEvents_PowerModeChanged(ByVal sender As Object, ByVal e As PowerModeChangedEventArgs)
Select Case e.Mode
Case PowerModes.Suspend
txtSuspend.Text = Now
Case PowerModes.Resume
txtResume.Text = Now
End Select
End Sub
End Class
Steps to detect when PC goes to sleep and wakes up in VB.NET.
.Net Framework 4.6.1
Windows Forms App
Visual Studio Community
Windows 10
#vbdotnet
----------------------
Imports Microsoft.Win32
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
AddHandler SystemEvents.PowerModeChanged, AddressOf SystemEvents_PowerModeChanged
End Sub
Private Sub SystemEvents_PowerModeChanged(ByVal sender As Object, ByVal e As PowerModeChangedEventArgs)
Select Case e.Mode
Case PowerModes.Suspend
txtSuspend.Text = Now
Case PowerModes.Resume
txtResume.Text = Now
End Select
End Sub
End Class



![VB.NET - Automate desktop apps with Sendkeys and Win32 functions
How I automate Windows desktop apps with VB.NET using Sendkeys and Win32 functions. It covers waiting until a specific window is active, explicit wait, simulating keyboard input with Sendkeys and simulating left click and right click.
#vbdotnet
Win32
Private Declare Function GetForegroundWindow Lib user32 () As IntPtr
Private Declare Auto Function GetWindowText Lib user32 (ByVal hWnd As System.IntPtr, ByVal lpString As System.Text.StringBuilder,
ByVal cch As Integer) As Integer
Public Declare Sub mouse_event Lib user32 (ByVal dwFlags As UInteger, ByVal dx As UInteger, ByVal dy As UInteger, ByVal dwData As UInteger,
ByVal dwExtraInfo As Integer)
Const MOUSEEVENTF_LEFTDOWN As UInteger = &H2
Const MOUSEEVENTF_LEFTUP As UInteger = &H4
Const MOUSEEVENTF_RIGHTDOWN As UInteger = &H8
Const MOUSEEVENTF_RIGHTUP As UInteger = &H10
Regex function
Regex.Replace(str, [+^%~(){}], {$0})
Sendkeys Codes
https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.sendkeys
0:00 Summary of automation tasks
0:20 Wait for active window
1:22 Sendkeys functions
2:45 Mouseclicks
3:32 Demo UI to run scripts VB.NET - Automate desktop apps with Sendkeys and Win32 functions](https://i.ytimg.com/vi/HS_PnrTKrwI/mqdefault.jpg)






