VBS SendKeys未发送“("字符

编程入门 行业动态 更新时间:2024-10-24 20:21:47
本文介绍了VBS SendKeys未发送“("字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

这里是新的,所以请对我放轻松:).我在下面使用此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未发送“("字符

本文发布于:2023-11-16 23:10:29,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1607881.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符   VBS   SendKeys   quot

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!