-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
RecordSession.ps1
52 lines (49 loc) · 1.44 KB
/
RecordSession.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
function Parse-KeyText ($Content) {
$Content = $Content.Replace("`r`n", "`n").Replace("`n", "{ENTER}")
[regex]$regex = '(?<modifiers>[+^%]+)?(?<content>{[^}]+}|[^+?^\^^%])'
$regex.Matches($Content) | % { $_.Value }
}
function Send-Keys ($KeyStrokes, $KeyPressSleep = 30, $LongSleep = 1500) {
$wshell = New-Object -ComObject wscript.shell
Sleep -Milliseconds 100
foreach ($KeyPress in $KeyStrokes)
{
if ($KeyPress -eq '{ALT}')
{
$KeyPress = '%'
}
elseif ($KeyPress -eq '{SHIFT}')
{
$KeyPress = '+'
}
elseif ($KeyPress -eq '{CTRL}')
{
$KeyPress = '^'
}
if ($KeyPress -eq '{SLEEP}')
{
Sleep -Milliseconds $LongSleep
}
else {
Sleep -Milliseconds $KeyPressSleep
$wshell.SendKeys($KeyPress)
}
}
}
#Documentation https://ss64.com/vb/sendkeys.html
$textToSend = @"
{SHIFT}{CTRL}t{SLEEP}cd D:\Users\Peter\source\repos\FluentTerminal
powersession rec -c "pwsh -nologo" recording.txt
{SLEEP}Import-Module PowerType
{SLEEP}Enable-PowerType
git c{SLEEP}{DOWN}{SLEEP}{DOWN}{SLEEP} m{SLEEP}{DOWN}{SLEEP}
{SHIFT}{CTRL}w
{SLEEP}exit
"@
Write-Host "Installing powertype"
Install-Module PowerType
Write-Host "Simulating"
$KeyStrokes = Parse-KeyText -Content $textToSend
Send-Keys -KeyStrokes $KeyStrokes
Write-Host "Uninstalling PowerType"
Uninstall-Module PowerType