Existem várias soluções para isso, mas esse código ajuda a tornar isso possível sem terceiros ferramentas de festa. Infelizmente, não podemos usar SendKeys porque o A chave Win
está indisponível.
Isso é um pouco hacky. O ideal seria que você desejasse consultar a resolução do monitor de destino e iniciar cada processo com a posição de pixel desejada.
# stuff needed to send keystrokes
$source = @"
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace KeyboardSend
{
public class KeyboardSend
{
[DllImport("user32.dll")]
public static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);
private const int KEYEVENTF_EXTENDEDKEY = 1;
private const int KEYEVENTF_KEYUP = 2;
public static void KeyDown(Keys vKey)
{
keybd_event((byte)vKey, 0, KEYEVENTF_EXTENDEDKEY, 0);
}
public static void KeyUp(Keys vKey)
{
keybd_event((byte)vKey, 0, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
}
}
}
"@
Add-Type -TypeDefinition $source -ReferencedAssemblies "System.Windows.Forms"
# the arrow key combinations (0 = Left Up, 1 = Left Down, 2 = Right Up, 3 = Right Down)
$LR = @('Left','Left','Right','Right')
$UD = @('Up','Down','Up','Down')
# edit the sleep value as needed.
$sleepMS = 200
# start a process, move it in the next desirable position, x4
0..3 | % {
Start-Process powershell
# if we don't wait for the process to open, we might not have focus.
Sleep -Milliseconds $sleepMS
[KeyboardSend.KeyboardSend]::KeyDown("LWin")
[KeyboardSend.KeyboardSend]::KeyDown($LR[$_])
Sleep -Milliseconds $sleepMS
[KeyboardSend.KeyboardSend]::KeyDown($UD[$_])
[KeyboardSend.KeyboardSend]::KeyUp("LWin")
Sleep -Milliseconds $sleepMS
[KeyboardSend.KeyboardSend]::KeyDown("Escape")
}