SendKeysMethod to Perform Keystrokes Inside PowerShell
SendWaitMethod to Perform Keystrokes Inside PowerShell
PowerShell is a powerful scripting language that can manage and automate different tasks in the system. It lets you send keystrokes from the console to the running application.
SendKeys Method to Perform Keystrokes Inside PowerShell
You can use the
SendKeys() method to send keystrokes to the active application.
AppActivate() method activates the application
Notepad so you can send keystrokes to it.
$wshell = New-Object -ComObject wscript.shell; $wshell.AppActivate('Notepad') $wshell.SendKeys('Hello World')
If you open the notepad and run the above code, the specified keys will be sent to the
SendWait Method to Perform Keystrokes Inside PowerShell
SendWait() method sends keystrokes to the active application and waits for the processes started by the keystrokes to be completed. It can be helpful when the other application needs to finish before the first one can proceed.
$wshell = New-Object -ComObject wscript.shell; $wshell.AppActivate('Notepad') [System.Windows.Forms.SendKeys]::SendWait('Hello~World')
~ character represents the Enter key. You can find codes to specify such action keys in this link.
The keystrokes are sent to the specified application after activating its window. We hope this tutorial helps you understand how to perform keystrokes inside PowerShell.