Keep Computer Active and MS Teams Green – Complete
16 July, 2025
Want to keep your Microsoft Teams status green even when you’re away from your computer?
I built a free, lightweight PowerShell tool that simulates real mouse activity — no clicking, no installs, and no admin rights needed. You just click two points on your screen… And enter how long you want it to run… And it moves your mouse between those points to keep your system awake — and your Teams status active. It even runs quietly in your system tray, and you can exit anytime. No shady apps. No background spyware. Just clean and simple PowerShell code you can inspect or customize.Download the executable free — and if this helps you, give it a like and consider subscribing.
Consider buying me a coffee
PowerShell Script:
# Mouse click injection setup
Add-Type -TypeDefinition @"
using System;
using System.Runtime.InteropServices;
public class MouseInput {
[StructLayout(LayoutKind.Sequential)]
public struct INPUT {
public int type;
public MOUSEINPUT mi;
}
[StructLayout(LayoutKind.Sequential)]
public struct MOUSEINPUT {
public int dx;
public int dy;
public int mouseData;
public int dwFlags;
public int time;
public IntPtr dwExtraInfo;
}
[DllImport("user32.dll", SetLastError = true)]
public static extern uint SendInput(uint nInputs, INPUT[] pInputs, int cbSize);
public const int INPUT_MOUSE = 0;
public const int MOUSEEVENTF_LEFTDOWN = 0x0002;
public const int MOUSEEVENTF_LEFTUP = 0x0004;
public static void Click() {
INPUT[] inputs = new INPUT[2];
inputs[0].type = INPUT_MOUSE;
inputs[0].mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
inputs[1].type = INPUT_MOUSE;
inputs[1].mi.dwFlags = MOUSEEVENTF_LEFTUP;
SendInput((uint)inputs.Length, inputs, Marshal.SizeOf(typeof(INPUT)));
}
}
"@
Add-Type -TypeDefinition @"
using System;
using System.Runtime.InteropServices;
public class ConsoleWindow {
[DllImport("kernel32.dll")]
public static extern IntPtr GetConsoleWindow();
[DllImport("user32.dll")]
public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
}
"@
# Load required UI libraries
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
# Prepare form to capture two clicks
$global:clickCount = 0
$global:pos = $null
$global:newPos = $null
$form = New-Object Windows.Forms.Form
$form.Opacity = 0.3
$form.WindowState = 'Maximized'
$form.TopMost = $true
$form.FormBorderStyle = 'None'
$form.ShowInTaskbar = $false
$form.BackColor = 'LightGray'
$label = New-Object Windows.Forms.Label
$label.Text = "Click twice to capture two mouse positions"
$label.AutoSize = $true
$label.ForeColor = 'Black'
$label.BackColor = 'LightGray'
$label.Font = 'Arial,20'
$label.Location = New-Object System.Drawing.Point(50, 50)
$form.Controls.Add($label)
$form.Add_MouseClick({
$click = [System.Windows.Forms.Cursor]::Position
if ($global:clickCount -eq 0) {
$global:pos = $click
Write-Host "Captured first click at: $($pos.X), $($pos.Y)"
$label.Text = "Click again to capture second position"
$global:clickCount++
} elseif ($global:clickCount -eq 1) {
$global:newPos = $click
Write-Host "Captured second click at: $($newPos.X), $($newPos.Y)"
$form.Close()
}
})
$form.ShowDialog()
# Prompt user for duration in minutes
[int]$durationMinutes = Read-Host "Enter how many minutes to run the automation"
# Calculate end time
$endTime = (Get-Date).AddMinutes($durationMinutes)
# Countdown before loop starts
Write-Host "`nStarting automation in 5 seconds..."
for ($i = 3; $i -gt 0; $i--) {
Write-Host "$i..."
Start-Sleep -Seconds 1
}
$consolePtr = [ConsoleWindow]::GetConsoleWindow()
[ConsoleWindow]::ShowWindow($consolePtr, 6) # 6 = Minimize
# Add a shared stop flag
$global:stopLoop = $false
# Add tray icon
$notifyIcon = New-Object System.Windows.Forms.NotifyIcon
$notifyIcon.Icon = [System.Drawing.SystemIcons]::Information
$notifyIcon.Text = "Automation Running (Right-click to Exit)"
$notifyIcon.Visible = $true
# Create context menu with Exit item
$exitItem = New-Object System.Windows.Forms.MenuItem "Exit"
$exitHandler = {
Write-Host "`nExit requested via tray icon."
Set-Variable -Name stopLoop -Value $true -Scope Global
}
$exitItem.add_Click($exitHandler)
$contextMenu = New-Object System.Windows.Forms.ContextMenu
$contextMenu.MenuItems.Add($exitItem)
$notifyIcon.ContextMenu = $contextMenu
# Prevent garbage collection
$global:notifyIcon = $notifyIcon
# Main loop (time-bound)
while ((Get-Date) -lt $endTime -and !$global:stopLoop) {
[System.Windows.Forms.Application]::DoEvents() # ← pump event queue
# Move to second position and click
[System.Windows.Forms.Cursor]::Position = $newPos
[MouseInput]::Click()
Start-Sleep -Seconds 10
# Move to first position and click
[System.Windows.Forms.Cursor]::Position = $pos
[MouseInput]::Click()
# Wait for 30 seconds, checking for exit every second
for ($i = 0; $i -lt 10; $i++) {
[System.Windows.Forms.Application]::DoEvents() # ← keep processing menu clicks
if ($global:stopLoop) { break }
Start-Sleep -Seconds 1
}
}
# Cleanup tray icon
$notifyIcon.Visible = $false
$notifyIcon.Dispose()
Write-Host "Automation completed or manually stopped."