首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >AppActivate并不总是激活应用程序窗口

AppActivate并不总是激活应用程序窗口
EN

Stack Overflow用户
提问于 2016-08-03 16:41:19
回答 1查看 2.2K关注 0票数 6

因此,我正在开发一些将使自动化的VBScript :打开它,导航和下载一个文件。我已经让它工作,但是有一个问题在于,我需要发送击键到它。SendKeys为我工作,但问题是,当我使用AppActivate来设置IE的焦点时,它并不总是有效的。基本上可以分为这两种情况:

案例1:双击我的.vbs文件,自动化过程顺利进行。窗口被激活,一切正常。

Case 2:双击我的.vbs文件,其他应用程序打开一个偷焦点的窗口(或者手动单击其他东西来更改焦点)。稍后执行AppActivate行时,IE永远不会聚焦,击键显然不会通过。

那么,你们对为什么AppActivate没有设置焦点有什么想法吗?

下面是我用来激活IE窗口的代码:

代码语言:javascript
运行
复制
Do While Not wshell.AppActivate("Active Agents - Internet Explorer")
    WScript.Sleep(1)
Loop
EN

Stack Overflow用户

发布于 2018-10-06 20:16:12

使用AppActivate焦点运行IE和发送键的脚本示例

代码语言:javascript
运行
复制
    'fuction to set the application active and then send keys 
    Function mySendKey(sKey,sTime)
       for i=0 to 600        ' this loop will continue about 30 sec if this not enough increase this number
        'get the window title of the IE
        title= sh.Exec("cmd.exe /c tasklist /v /fi ""imagename EQ iexplore*"" /FO LIST | FIND /i ""window title:"" ").stdOut.readline
        title= Mid (title,15,len(title)-14)
        sh.Popup  title,1

        Sh.AppActivate title
        Rtn=Sh.AppActivate(title)     '  window title of application
        If Rtn = True  Then           'if the window active then execute sned keys
            Sh.SendKeys  sKey                                     
            Exit For 
        End If
        wscript.sleep 10                              
      Next
     WScript.Sleep sTime*1000
    End Function

  'hide the cmd window from popup 
  If StrComp(right(WScript.FullName,11),"wscript.exe",1) = 0 Then    
  WScript.Quit CreateObject("WScript.Shell").Run("cscript.exe //nologo """ & WScript.ScriptFullName & """", 0, False)
  End If 
  'open internet explorer   
Set Sh = CreateObject("WScript.Shell")
Sh.Exec "C:\Program Files\Internet Explorer\iexplore.exe"
WScript.Sleep 7000
 'call mySendKey function to send keys to IE  
 Call mySendKey("(% )(x)",1)                         'max the windows of IE
 Call mySendKey("({F6})(www.yahoo.com)    (~)",10)   'browse to yahoo and wait 10 sec to load
 Call mySendKey("({F6})(www.msn.com)      (~)",10)   'browse to msn and wait 10 sec to load 
 Call mySendKey("(% )(C)",1)                         'close the IE
票数 2
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38749304

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档