简体   繁体   中英

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.

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. 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.

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.

According to the documentation, the correct way is to enclose it in curly braces as @user1071777 said.

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 "{+}".

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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