PowerShell script can simulate keyboard stroke.
This behavior can automate applications which do not support command line.
At this time, I made a script which run Notepad, input text and save it as a file.
Code
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 |
#Press Windows key [System.Windows.Forms.SendKeys]::SendWait("^{ESC}") #Input "run" [System.Windows.Forms.SendKeys]::SendWait("run") Start-Sleep -s 1 #Press Enter key [System.Windows.Forms.SendKeys]::SendWait("{ENTER}") Start-Sleep -s 1 #Input "notepad" [System.Windows.Forms.SendKeys]::SendWait("notepad") [System.Windows.Forms.SendKeys]::SendWait("{ENTER}") Start-Sleep -s 1 #Input "This is a test script" [System.Windows.Forms.SendKeys]::SendWait("This is a test script.") #Press Control+S key [System.Windows.Forms.SendKeys]::SendWait("^s") Start-Sleep -s 1 [System.Windows.Forms.SendKeys]::SendWait("newtext.txt") [System.Windows.Forms.SendKeys]::SendWait("{ENTER}") Start-Sleep -s 1 #Press Alt+F4 key [System.Windows.Forms.SendKeys]::SendWait("%{F4}") |
Explanation
This script just press keys by SendKeys.
The following page is the detail about keys.
VBScript - SendKeys Method - TechNet Articles - United States (English) - TechNet Wiki
Pressing Windows key cannot be simulated with another key. The script press Control+ESC, then input "run" and press enter.
In addition, there is a delay between pressing a key and showing dialog. A wait (1 second) may be needed to input a string.
Movie
The script is executed fast.
Basically, writing text and save it is done by a script (Not necessary to control GUI). However I made a script as an experiment.