powershell - Powershell【System.Windows.Forms.SendKeys】,发送shift+windowsKey+rightArrow组合
问题描述
在 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 键,但这似乎不起作用。
知道如何做到这一点吗?
解决方案
试试这个解决方案。它具有按下窗口键,以便您可以发送组合键。
**对我来说 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("Shift")
[KeySends.KeySend]::KeyDown("$Key")
[KeySends.KeySend]::KeyUp("LWin")
[KeySends.KeySend]::KeyUp("Shift")
}
WinKey({Right})
推荐阅读
- java - Redis (jedis) 无法删除带下划线的键
- sql - Postgres CROSSTAB 查询无法获得所有预期的列
- javascript - 无法访问的语句,menuItem.setActionView(R.layout.theme_switch);
- javascript - 您如何在没有闪存的护照的完成方法中访问消息/在反应应用程序中?
- angular - 使用 Angular 10 的角度材料的 mat-icon 时出错
- windows - 如何检测 Word.Application.SaveAs 超时?
- javascript - 仅当内容与特定值匹配时才渲染 VUE 槽
- azure-devops - Azure CI 管道 - DotNetCoreCLI@2 任务错误
- javascript - 使用 JSON 在 Python 和 JavaScript 之间进行通信以更改网站的 CSS
- spring-boot - Spring Boot 2 OpenAPI 3 文档的自定义模式