C# 如何使用发送键将 Ctrl+Shift+F1 发送到应用程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13557733/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 08:59:55  来源:igfitidea点击:

How to Send Ctrl+Shift+F1 to an application using send keys

c#winformssendkeys

提问by Mohd Zubair

I want to send Ctrl+Shift+F1combination of keys to an application.

我想将Ctrl+ Shift+F1组合键发送到应用程序。

But when I try to send the keys i am getting an error,the error is, ^+F1is not a valid key.

但是当我尝试发送密钥时出现错误,错误^+F1是不是有效密钥。

The code I am using is:

我正在使用的代码是:

System.Windows.Forms.SendKeys.Send("{^+F1}");

采纳答案by Mark Hall

Looking at the documentationyou need to have your braces around just the F1. Try this to see if it works

查看文档,您需要在 F1 周围戴上大括号。试试这个,看看它是否有效

System.Windows.Forms.SendKeys.Send("^+{F1}");

From above link by enclosing the ^ and + in the braces you are sending the literal character.

从上面的链接通过将 ^ 和 + 括在大括号中,您要发送文字字符。

The plus sign (+), caret (^), percent sign (%), tilde (~), and parentheses () have special meanings to SendKeys. To specify one of these characters, enclose it within braces ({})

加号 (+)、插入符号 (^)、百分号 (%)、波浪号 (~) 和括号 () 对 SendKeys 具有特殊含义。要指定这些字符之一,请将其括在大括号 ({}) 中

added by barlop - explanatory note-

由 barlop 添加 - 解释性说明 -

(from the documentation link above)

(来自上面的文档链接)

SHIFT +
CTRL ^
ALT %

and

F1 {F1}
F2 {F2}