Powershell [System.Windows.Forms.SendKeys], 发送 shift+windows 键+右箭头组合

Powershell [System.Windows.Forms.SendKeys], send shift+windowsKey+rightArrow combination

在 powershell 中,我使用 [System.Windows.Forms.SendKeys] 发送击键。但是我在模拟 windows 键时遇到了问题。因为它不是我在文档列表中找到的键之一:

https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.sendkeys?view=netcore-3.1

在这个 post 中,我看到他们正在使用 ctrl+esc 模拟 windows 键,但这似乎不起作用。

Sending Windows key using SendKeys

知道如何完成这个吗?

试试这个解决方案。它按下 window 键,这样你就可以发送组合键。

** 对我来说,Win + 右箭头键有效,但 shift 对我的机器没有任何影响。它可能适合你。

$source = @"
using System;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace KeySends
{
    public class KeySend
    {
        [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"
Function WinKey ($Key)
{
    [KeySends.KeySend]::KeyDown("LWin")
    [KeySends.KeySend]::KeyDown("ShiftKey")
    [KeySends.KeySend]::KeyDown("$Key")
    [KeySends.KeySend]::KeyUp("LWin")
    [KeySends.KeySend]::KeyUp("ShiftKey")
}

WinKey({Right})

.NET System.Windows.Forms Keys list