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

Viewed 2127
1 Answers

Try this solution. It has press down window key so that you can send combination key along with that.

**for me Win + Right Arrow key worked but shift doesn't have any effect on my machine. It might work for you.

$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

Related