返回列表 发帖

[问题求助] [已解决]VBS如何通过SendKeys的方式发送出剪切板的内容?

本帖最后由 xgda 于 2014-7-1 20:25 编辑

有一目标窗口,不能使用 ctrl+v 来粘贴剪切板的内容
也就是说不能使用  a.SendKeys "^v"
但能使用键盘敲出来

剪切板的内容为字母加数字,没有中文和符号
如剪切板的内容为 abcdefg
那就是 a.SendKeys "abcdefg"
但不能使用a.SendKeys "^v"

怎么才能用a.SendKeys的方式发送出剪切板的内容
1

评分人数

    • Batcher: 感谢给帖子标题标注[已解决]字样PB + 2

已经好了,非常感谢   yu2n   坛友
' 延时
WScript.Sleep 3000
Dim wso, objHTML, strClipboardText
Set wso = CreateObject("Wscript.Shell")
Set objHTML = CreateObject("htmlfile")
strClipboardText = objHTML.ParentWindow.ClipboardData.GetData("text")
'测试
'strClipboardText = "测试 A1 + C2 = 100% ? "
' 方法一:直接 Ctrl + V
wso.SendKeys "^v"
wso.SendKeys "~"
' 方法二:拆分成单个字符发送,只支持按键字符(A-z,0-9,英文标点),会受输入法限制
Dim i, strKey
If Not strClipboardText = "" Then
  For i = 1 To Len(strClipboardText)
    ' 拆分成单个字符
    strKey = Mid(strClipboardText, i, 1)
    WScript.Sleep 300
    ' 判断字符是否支持
    If ASCW(strKey) > 0 And ASCW(strKey) < 127 Then
      '' 特殊符号 + ^ % ~ 的处理
      If InStr("+^%~", strKey) > 0 Then strKey = "{" + strKey + "}"
      '' 发送按键码
      wso.SendKeys strKey
    End If
  Next
End If
Set wso = Nothing
Set objHTML = NothingCOPY

TOP

本帖最后由 yu2n 于 2015-1-3 20:25 编辑

2015.01.03 更新:特殊字符“ +^%~(){} ”的处理 ..
http://bathome.net/redirect.php? ... 6&fromuid=53540
1

评分人数

『千江有水千江月』千江有水,月映千江;万里无云,万里青天。    http://yu2n.qiniudn.com/

TOP

返回列表