Powershell [System.Windows.Forms.SendKeys],发送shift + windowsKey + rightArrow组合

问题描述 投票:0回答:1

在powershell中,我正在使用[System.Windows.Forms.SendKeys]发送击键。但是我在模拟Windows键时遇到了麻烦。由于它不是我在文档列表中找到的键之一:

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

在这篇文章中,我看到他们正在使用ctrl + esc模拟Windows键,但这似乎不起作用。

Sending Windows key using SendKeys

任何想法如何做到这一点?

powershell sendkeys
1个回答
0
投票

尝试此解决方案。它具有按下窗口键,因此您可以与此同时发送组合键。

**对我来说,赢+右箭头键有效,但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 Win ($Key)
{
    [KeySends.KeySend]::KeyDown("LWin")
    #[KeySends.KeySend]::KeyDown({SHIFT})
    [KeySends.KeySend]::KeyDown("$Key")
    [KeySends.KeySend]::KeyUp("LWin")
    #[KeySends.KeySend]::KeyUp({SHIFT})
}
Win({Right})
© www.soinside.com 2019 - 2024. All rights reserved.