ALDomanpi
ALDomanpi

Reputation: 1

What is the powershell code to simulate pressing the windows key?

I'm trying to make a .ps1 program to auto-refresh a site in edge - and I also want it to position the window. I need it to simulate pressing Win+RIGHT but I cant find the code for the windows key.

$wshell.SendKeys('{??????}')

Upvotes: 0

Views: 7383

Answers (3)

user18432
user18432

Reputation: 49

The AutoIt answer works as expected as SendKeys is able to press the windows key but not windowskey + another key.

Download the AutoIt zip and save the AutoItX folder to a permanent location:

https://www.autoitscript.com/site/autoit/downloads/

Example code to press windowskey + e:

Import-Module "C:\Path\AutoItX\AutoItX.psd1"

Initialize-AU3

Send-AU3Key -Key "{LWINDOWN}e{LWINUP}" -Mode 0

(I would have posted this as a comment to the existing AutoIt answer but I don't have the 50 reputation yet, sorry)

Upvotes: 0

postanote
postanote

Reputation: 16116

The keybinding to use with SendKeys for the Windows Key is this:

# Activating the Windows Key
Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.SendKeys]::SendWait('^{ESC}')

Upvotes: 1

William Higgs
William Higgs

Reputation: 191

Personally, if I were you, I would use the Autoit powershell module to accomplish this task. If you download the zip file, you will want to extract the directory "install\AutoitX" in the zip file to some location on your computer. Be sure to unblock the zip file before you do, of course. Then, import the autoit powershell module, and you can send emulate pressing the keys you mentioned with the following code:

Initialize-AU3
Send-AU3Key -Key "#{RIGHT}" -Mode 0

Upvotes: 0

Related Questions