Created
July 13, 2018 17:05
-
-
Save arkag/003298ccd84b8b86d81797b362854b26 to your computer and use it in GitHub Desktop.
Simulates typing and backspacing on one line
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function New-BackspaceLn { | |
| [CmdletBinding()] | |
| Param ([String]$Sentence) | |
| $Backspaces = "`b" * $Sentence.Length | |
| return "$Sentence$Backspaces" | |
| } | |
| function Write-HostSimType { | |
| [CmdletBinding()] | |
| Param([String]$TypeMe, [Switch]$KeepMe) | |
| if (!$KeepMe){$TypeMe = New-BackspaceLn $TypeMe} | |
| $charr = $TypeMe.ToCharArray() | |
| foreach ($l in $charr){ | |
| $delay = 25 | |
| if (@(",",".","?","!") -Contains $l){ | |
| $delay = 300 | |
| } elseif ($l -Match "`b" ){ | |
| $l = "`b `b" | |
| } | |
| Write-Host -NoNewLine $l | |
| Start-Sleep -Milliseconds $delay | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment