AlwaysOnTop.psm1
<#
.Synopsis Keeps a particular window in main focus and prevents other windows from stealing the focus .DESCRIPTION Saw someone I know tweet a real dilemma. That they were so pi$$ed off about other windows taking focus whilst they had been typing, then all that typing had been lost. No more my friends. Eliminate real-world problems with this module. Keeping a single window in main focus all the time until you press CTRL+SPACEBAR to un-focus the window. .EXAMPLE Invoke-AlwaysOnTop -ProcessID 600 .EXAMPLE 600 | Invoke-AlwaysOnTop .EXAMPLE Focus 600 #> function Invoke-AlwaysOnTop { [CmdletBinding()] [Alias('Focus')] [OutputType([int])] Param ( # Param1 help description [Parameter(Mandatory=$true, ValueFromPipeline=$true, Position=0)] [ValidateScript({if(Get-Process -id $ProcessID){$true}else{throw "$ProcessID is not a valid running PID please try again"}})] [int]$ProcessID ) Begin { [void] [System.Reflection.Assembly]::LoadWithPartialName("'Microsoft.VisualBasic") [void] [System.Reflection.Assembly]::LoadWithPartialName("'System.Windows.Forms") Start-Process -FilePath "$($PWD.Path)\always-on-top.exe" Write-Host -ForegroundColor Green "always-on-top process has been started" } Process { [Microsoft.VisualBasic.Interaction]::AppActivate($ProcessID) Start-Sleep -Milliseconds 666 [System.Windows.Forms.SendKeys]::SendWait("^ ") } End { Write-Host -ForegroundColor Green "Press CTRL+SPACE on the always on top window to un-focus it. Thank you" } } |