########## PowerShell: Unattended key press #simulate not away presence status available "mouse jiggle" or wiggle #Copyright (c) All Rights Reserved #www.leedesmond.com #2023-01-15 Version: 1.0 param($IntervalInSeconds=15, [string[]]$Keys=@('+{F15}','+{F14}','+{F13}'),[switch]$NoNewline) function SimulateKeyPress() { param($IntervalInSeconds,[string[]]$Keys,[switch]$NoNewline) if($IntervalInSeconds -is [string] -or $IntervalInSeconds -le 0){ #-or $IntervalInSeconds -isnot [int] Write-Host "Usage: script.ps1 -IntervalInSeconds N #where N > 0"; return;} $dateStart=Get-Date; $elapsed="00:00:00"; Write-Host "Start: $dateStart"; $wsh=New-Object -ComObject WScript.Shell; $KeysLen=$Keys.Length-1; while($IntervalInSeconds -gt 0){ $index=Get-Random -Minimum 0 -Maximum $KeysLen; $wsh.SendKeys($Keys[$index]); #$logonUI=$false; try{Get-Process LogonUI -EA:Stop|Out-Null;$logonUI=$true;}catch{$logonUI=$false;} Write-Host ` "($((Get-Date).ToString()) elapsed: $elapsed key: $($Keys[$index]) " ` "IntervalInSeconds: $IntervalInSeconds LogonUI: $logonUI) " ` -NoNewline:$NoNewline; Start-Sleep -Seconds $IntervalInSeconds; $dateNow=Get-Date; $elapsed=$dateNow-$dateStart; $elapsed="{0:d2}:{1:d2}:{2:d2}" -f $elapsed.Hours,$elapsed.Minutes,$elapsed.Seconds; } } #SimulateKeyPress() SimulateKeyPress -IntervalInSeconds $IntervalInSeconds -Keys $Keys -NoNewline:$NoNewline;