转义大括号似乎在 SendKeys 中不起作用

Escaping braces doesn't seem to work in SendKeys

向 VSCode 发送密钥时我没有收到 {}:

$wshell = New-Object -ComObject wscript.shell;
$wshell.AppActivate('Untitled-1')
Sleep 1
$wshell.SendKeys('`{`}')
Sleep 1
$wshell.SendKeys('Hello World 2~')

在这种情况下,您必须避开大括号的不是 PowerShell。是 SendKeys。

要在 SendKeys 中使用文字大括号,您必须像其他特殊字符一样将它们括在大括号中。

$wshell.SendKeys('{{}{}}')

来自MSDN

The plus sign (+), caret (^), percent sign (%), tilde (~), and parentheses () have special meanings to SendKeys. To specify one of these characters, enclose it within braces ({}). For example, to specify the plus sign, use "{+}". To specify brace characters, use "{{}" and "{}}". Brackets ([ ]) have no special meaning to SendKeys, but you must enclose them in braces. In other applications, brackets do have a special meaning that might be significant when dynamic data exchange (DDE) occurs.

强调我的。