Skip to content

Instantly share code, notes, and snippets.

@arkag
Created July 13, 2018 17:05
Show Gist options
  • Select an option

  • Save arkag/003298ccd84b8b86d81797b362854b26 to your computer and use it in GitHub Desktop.

Select an option

Save arkag/003298ccd84b8b86d81797b362854b26 to your computer and use it in GitHub Desktop.
Simulates typing and backspacing on one line
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