How to Send Keys using PowerShell and WScript (Simulate Keystrokes) | ninjasquad
Sometimes, you want to emulate keystrokes (key presses) for example, you want to automate some tasks which are easier to do by repeating keystrokes than looking up APIs and write a decent script/program. For example, you want to open any chat and type in “Hello!” 100 times, you can write a script using Powershell, which first sleeps a few seconds, and then simulate keystrokes:
You can do this via Creating a Wscript.Shell COM (Component Object Model) object on Windows using Powershell script.
$WShell = New-Object -com "Wscript.Shell" $WShell.sendkeys("Hello!")
To repeat 100 times, simply do this in Powershell (FOR loop):
$WShell = New-Object -com "Wscript.Shell" for (($i = 0), ($j = 0); $i -lt 10; $i++) { $WShell.sendkeys("Hello!") $WShell.sendkeys("{ENTER}") }
Powershell Script to Stay Online using Keystrokes
Based on this, we can send Scroll-Lock Keystrokes every few interval until script is terminated/killed. Some keyboards don’t even have this scroll-lock keys. The idea is to emulate the keystrokes so that your chat applications (Microsoft Teams, Slack, Discord, Google Chats, Telegram etc) assume you are still online – and thus will not make your status to “Away” (AFK – Away From Keyboard).
$WShell = New-Object -com "Wscript.Shell" while ($true) { $WShell.sendkeys("{SCROLLLOCK}") Start-Sleep -Milliseconds 100 $WShell.sendkeys("{SCROLLLOCK}") Start-Sleep -Seconds 120 }
–EOF (The Ultimate Computing & Technology Blog) —
GD Star Rating
loading…
326 words
Last Post: Teaching Kids Programming – Count Distinct Numbers on Board (Recursion, Simulation, Math, Hash Set)
Source: Internet