简体   繁体   English

C#Sendkeys如何发送波浪号而不发送回车

[英]C# Sendkeys how to send tilde without sending enter

In my code, I am trying to send a tilde (~) to the users program. 在我的代码中,我试图将波浪号(〜)发送到用户程序。 Everytime I send ~ it presses enter and the code does not get to continue sending the rest of the keys. 每次发送〜时,它都会按Enter键,但代码无法继续发送其余键。

I have tried: 我努力了:

SendKeys.SendWait("([~])");
SendKeys.SendWait("~");
SendKeys.SendWait("{[~]}");

they all just press the enter button and don't send the actual tilde 他们都只是按回车按钮,而不发送实际的波浪号

The documentation says: 文件说:

The plus sign (+), caret (^), percent sign (%), tilde (~), and parentheses () have special meanings to SendKeys. 加号(+),脱字号(^),百分号(%),代字号(〜)和括号()对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. 括号([])对SendKeys没有特殊含义,但是必须将其括在括号中。

So this should work: 所以这应该工作:

SendKeys.SendWait("{~}");

The documentation also remarks: 该文档还指出:

If your application is intended for international use with a variety of keyboards, the use of Send could yield unpredictable results and should be avoided. 如果您的应用程序打算与各种键盘一起在国际上使用,则使用Send可能会产生不可预测的结果,应避免使用。

According to the documentation, the correct way is to enclose it in curly braces as @user1071777 said. 根据文档,正确的方法是将其括在大括号中,如@ user1071777所述。

The plus sign (+), caret (^), percent sign (%), tilde (~), and parentheses () have special meanings to SendKeys. 加号(+),脱字号(^),百分号(%),代字号(〜)和括号()对SendKeys具有特殊含义。 To specify one of these characters, enclose it within braces ({}). 要指定这些字符之一,请将其括在大括号({})中。 For example, to specify the plus sign, use "{+}". 例如,要指定加号,请使用“ {+}”。

Source: http://msdn.microsoft.com/en-us/library/system.windows.forms.sendkeys.send(v=vs.110).aspx 来源: http : //msdn.microsoft.com/en-us/library/system.windows.forms.sendkeys.send(v=vs.110).aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM