是否同时按下Windows徽标键+ Powershell中的Alt + PrtScn?

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

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

我需要任何更改吗?

$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# powershell powershell-ise pester
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.