-
Notifications
You must be signed in to change notification settings - Fork 28
/
Invoke-AutoType.ps1
47 lines (35 loc) · 1.5 KB
/
Invoke-AutoType.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
<#
feat: Add PowerShell script for automating typing
This commit adds a new PowerShell script, `Invoke-AutoType.ps1`, which allows for automating typing on both Windows and macOS operating systems. The script takes a string as input and types it character by character with a small delay between each character.
The script includes separate logic for Windows and macOS, utilizing the `System.Windows.Forms.SendKeys` class for Windows and AppleScript for macOS.
This feature will be useful for automating repetitive typing tasks, such as filling out forms or entering text in applications.
#>
# The string to type
$type = ''
$sleepMillisecondsBetweenCharacters = 1
# Sleep for 5 seconds before starting to type to go to the right window
Start-Sleep -Seconds 5
# If Operating System is Windows
if ($IsWindows) {
# Loop over each character in the string
foreach ($char in $type.ToCharArray()) {
# Send the character
[System.Windows.Forms.SendKeys]::SendWait($char)
# Sleep for 5 milliseconds between characters
Start-Sleep -Milliseconds $sleepMillisecondsBetweenCharacters
}
}
if ($IsMacOS) {
# Boucle sur chaque caractère de la chaîne
foreach ($char in $type.ToCharArray()) {
$script = @"
tell application "System Events"
keystroke "$char"
end tell
"@
}
# Exécution du script AppleScript pour chaque caractère
osascript -e $script
# Pause de 5 millisecondes entre les caractères
Start-Sleep -Milliseconds $sleepMillisecondsBetweenCharacters
}