Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
822 views
in Technique[技术] by (71.8m points)

vb.net - How to send "{" or "}" signs through send keys method in vb 2010

I want to send { and } signs to the Active window in Visual Basic 2010.But the problem is when we send a key like "Backspace" we send it as "{BS}".So it also contains the { & } signs. Therefore when we send { and } signs nothing happen.Anyone help me...

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

From

http://msdn.microsoft.com/en-us/library/system.windows.forms.sendkeys.aspx

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.

Basically, you need to double up the braces to escape them, Like

{{}

to send a { opening brace, and

{}} 

to send a closing brace. It may not be obvious at first glance, but that's just enclosing a brace character within braces. This is consistent with other escape sequences, such as using \ in C/C#/etc to indicate a literal instead of a string formatting character.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...