Author Posts

December 9, 2017 at 7:29 pm

Hi, I used Autohotkey to script small Things for myself and I am Aware that this Task could be done with Autohotkey without Problems. However I Need to provide a script on many machines and would like to use Powershell instead so I do not Need to install Autohotkey everywhere.

Task is:

1. User has to select some text in browser or other window
2. Press Hotkey, for example F12 on Keyboard to trigger script
3. SCRIPT: send Ctrl+X to grab selected text .
4. SCRIPT: replace dedicated character (for example #) with other string (CR/LR)
5. SCRIPT: send Ctrl+V to paste modified text at same place where source text was

I am just wondering if Powershell can do this, as I am newbie on Powershell. If anybody could confirm that this is possible I will dig into scrpting hoping to solve this

December 9, 2017 at 9:28 pm

This has been possible ever since the VBScript days.
It's called SendKeys, though it does get panned by many over the years. I've had no real issues in using it.

In PowerShell, it is just doing this.. Say, some Windows UI

### Start PowerUser Menu
[void] [System.Reflection.Assembly]::LoadWithPartialName("'System.Windows.Forms")
[System.Windows.Forms.SendKeys]::SendWait("^{ESC}+X")

A quick search using your favorite search engine, using the strings

'VBScript SendKeys'
'PowerShell SendKeys'

... Will provide you a long list of articles to choose from.

Also take a look at the WASP module, here:
'wasp.codeplex.com'