这里是新的,所以请对我放轻松:).我在下面使用此VB脚本在记事本上输入数据时遇到了奇怪的问题.我使用"SendKeys"发送到记事本的代码每次都会更改.我注意到脚本工作得很好,除非我发送的文本包含("或)",并且如果发生这种情况,我会收到错误消息无效的过程调用或参数",并且仅显示文本.
am new here so please take it easy on me :). i have strange issue using this VB script below to enter data on a Notepad. The code i send using the "SendKeys" to the notepad is changed every time. i noticed the script working great except if the text i send is containing the "(" or ")" and if that happen i get error "Invalid procedure call or argument" and only have of the text print.
我的部分代码在下面(我无法完全附上它):
part of my code is below ( i couldn't attach it fully ):
Wscript.Sleep 300 objShell.SendKeys "zDYg8/bY)b6Ox$z" 推荐答案objShell.SendKeys "zDYg8/bY{)}b6Ox$z"
阅读并遵循 SendKeys 方法参考:
Read and follow SendKeys method reference:
SendKeys方法使用一些字符作为字符的修饰符(而不是使用其面值).这套特殊字符由括号,方括号,花括号和以下字符组成:
The SendKeys method uses some characters as modifiers of characters (instead of using their face-values). This set of special characters consists of parentheses, brackets, braces, and the:
- 加号"+",
- 插入符号"^",
- 百分号%",
- 和波浪号〜".
通过将这些字符括在大括号"{}"中来发送这些字符.
Send these characters by enclosing them within braces "{}".
修改.给出了针对特定字符串 literal 的答案.
Edit. The answer was given for a particular string literal.
使用替换功能或替换方法(VBScript)将字符串变量修改为符合 SendKeys 的格式,例如如以下代码段所示:
Use either Replace Function or Replace Method (VBScript) to modify a string variable to SendKeys-compliant format, e.g. as in the following code snippet:
sString = "zDYg(8/bY)b6Ox$z" sStringToSend = Replace( Replace( sString, ")", "{)}"), "(", "{(}") objShell.SendKeys sStringToSend编辑#2 :括号需要特殊处理,并且必须首先处理!
Edit #2: braces require special treatment, and must be handled first!
sStringGiven = "zDYg(8/bY)b6Ox$z" ' braces require special treatment, and must be handled first! sStringAux = "" For ii = 1 To Len( sStringGiven) sChar = Mid( sStringGiven, ii, 1) Select Case sChar Case "{", "}" ''' braces sStringAux = sStringAux & "{" & sChar & "}" Case Else sStringAux = sStringAux & sChar End Select Next ' Then, special characters other than braces might be handled in any order ' in a nested `replace` functions, or sequentially: sStringAux = Replace( Replace( sStringAux, "^", "{^}" ), "%", "{%}" ) sStringAux = Replace( Replace( sStringAux, "+", "{+}" ), "~", "{~}" ) sStringAux = Replace( Replace( sStringAux, "[", "{[}" ), "]", "{]}" ) sStringToSend = Replace( Replace( sStringAux, ")", "{)}" ), "(", "{(}" ) objShell.SendKeys sStringToSend编辑#3-最终解决方案:完全省略 Replace :
sStringGiven = "zDYg(8/bY)b6Ox$z" sStringToSend = "" For ii = 1 To Len( sStringGiven) sChar = Mid( sStringGiven, ii, 1) Select Case sChar Case "{", "}", "(", ")", "[", "]", "^", "%", "+", "~" sStringToSend = sStringToSend & "{" & sChar & "}" Case Else sStringToSend = sStringToSend & sChar End Select Next objShell.SendKeys sStringToSend更多推荐
VBS SendKeys未发送“("字符
发布评论