Skip to content

Commit e8a7c29

Browse files
committed
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.
1 parent 590f16d commit e8a7c29

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

Invoke-AutoType.ps1

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
2+
<#
3+
feat: Add PowerShell script for automating typing
4+
5+
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.
6+
7+
The script includes separate logic for Windows and macOS, utilizing the `System.Windows.Forms.SendKeys` class for Windows and AppleScript for macOS.
8+
9+
This feature will be useful for automating repetitive typing tasks, such as filling out forms or entering text in applications.
10+
#>
11+
12+
# The string to type
13+
$type = ''
14+
15+
$sleepMillisecondsBetweenCharacters = 1
16+
17+
# Sleep for 5 seconds before starting to type to go to the right window
18+
Start-Sleep -Seconds 5
19+
20+
# If Operating System is Windows
21+
if ($IsWindows) {
22+
# Loop over each character in the string
23+
foreach ($char in $type.ToCharArray()) {
24+
# Send the character
25+
[System.Windows.Forms.SendKeys]::SendWait($char)
26+
27+
# Sleep for 5 milliseconds between characters
28+
Start-Sleep -Milliseconds $sleepMillisecondsBetweenCharacters
29+
}
30+
}
31+
32+
if ($IsMacOS) {
33+
# Boucle sur chaque caractère de la chaîne
34+
foreach ($char in $type.ToCharArray()) {
35+
$script = @"
36+
tell application "System Events"
37+
keystroke "$char"
38+
end tell
39+
"@
40+
}
41+
42+
# Exécution du script AppleScript pour chaque caractère
43+
osascript -e $script
44+
45+
# Pause de 5 millisecondes entre les caractères
46+
Start-Sleep -Milliseconds $sleepMillisecondsBetweenCharacters
47+
}

0 commit comments

Comments
 (0)