Functions/Scraping/Send-Keystrokes.ps1
Function Send-Keystrokes { [CmdletBinding()] Param ( # String to send as keystrokes [Parameter(Mandatory=$True,ValueFromPipeline=$true)] [String] $InputObject, # Time Delay in Seconds [Parameter(Mandatory=$false)] [Int] $Countdown = 5 ) Begin { # Add the Forms Assembly to the environment Add-Type -AssemblyName System.Windows.Forms # Send selector warning to the user for ($s = $Countdown; $s -gt 1; $s--) {Write-Progress -Activity "Preparing to send keys" -CurrentOperation "Click the cursor/context you want to start printing into" -SecondsRemaining $s -PercentComplete (($Countdown-$s)/3*100); start-sleep -Seconds 1} } Process { # Convert special characters of the string $ConvString = $InputObject | Format-SendKeys # Send each character of the given string as a key input $complete = $false while (!$complete) { [System.Windows.Forms.SendKeys]::SendWait("$InputObject") $complete = $true } } } |