首页 > 解决方案 > Powershell中的Windows徽标键+ Alt + PrtScn同时按下多个键?

问题描述

我通过引用链接尝试了以下代码,但无法一次按下这些键。

我需要任何改变吗?

$code = @'
namespace SendTheKeys {
  class SendIt {
   public static void Main(string[] args) {
    [System.Runtime.InteropServices.DllImport("user32.dll")]
        private 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"
[KeyboardSend.KeyboardSend]::KeyDown("LWin")
[KeyboardSend.KeyboardSend]::KeyDown("Alt") 
[KeyboardSend.KeyboardSend]::KeyDown("PrintScreen")
[KeyboardSend.KeyboardSend]::KeyUp("LWin") 
[KeyboardSend.KeyboardSend]::KeyUp("Alt")

标签: c#powershellpowershell-isepester

解决方案


看看这段代码:https ://github.com/stefanstranger/PowerShell/blob/master/WinKeys.ps1

我假设您应该能够使用“Win”功能Win "%{PRTSC}"来获得您想要的东西


推荐阅读