在写脚本过程中,经常发现后台发送字符串不可用或不可靠,经多次试验,发现要是分两步走,还是可以实现正常后台发送字符串的,请参见下面脚本及解释(节选,非完整代码),只要看汉字部分:
bdxhx= Plugin.Window.Search("打开")
//遍历标题为“打开”的窗口
Delay 300
bdxhxwin = Split(bdxhx, "|")
Delay 100
If UBound(bdxhxwin) < 1 Then
Goto biaoji01
End if
//这里本来是一大堆判断条件,将不同的字符串赋值给变量hxname
hxname = "ABCDEF.path"
//下面一段是找“打开”父窗口下的一个输入子窗口句柄(hxinput)和一个打开按钮句柄(mksure)
mksure = 0 : hxinput = 0 : handle0 = 0
While mksure = 0 or hxinput = 0
handle = Plugin.Window.FindEx(bdxhxwin(0),handle0,0,0)
s1 = Plugin.Window.GetClass(handle)
s2 = Plugin.Window.GetText(handle)
//MessageBox "句柄 "& handle&"类名 "&s1&"标题 "&s2
//Delay 2000
If s1 = "Button" and s2 = "打开(&O)" Then
mksure = handle
ElseIf s1 = "ComboBoxEx32" Then
hxinput = handle
End if
handle0=handle
Wend
//下面是向输入框输入字符串变量hxname,请注意就是下面这行很重要,先输入一个空格字符,有了它,真正的字符串才能正常输入,否则不行。
Call Plugin.Bkgnd.SendString(hxinput," ")
Delay 50
//下面一句就是写入字符串,如果对字符串前端有严格要求,这里要加一句后台按退格键
Call Plugin.Bkgnd.SendString(hxinput,hxname)
Delay 6000
//下面点“打开”按钮
Call Plugin.Bkgnd.LeftClick(mksure,37,12)
Delay 5000