VBScript - 使用 AppActivate 将焦点切换到窗口 [英] VBScript - switching focus to window using AppActivate

查看:37
本文介绍了VBScript - 使用 AppActivate 将焦点切换到窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有多台电视,每台电视都连接到不同的计算机.目标是在通过两个应用程序循环的连续循环上显示/设置焦点.这必须在所有电视上同步.最初,我通过发送 alt+esc 键来设置它在任务栏中的所有应用程序中循环.效果很好,但很难在所有电视上同步.所以我使用 AppActivate 来设置焦点并根据偶数/奇数分钟在窗口之间切换.它现在已同步,但屏幕似乎每秒都在尝试将焦点设置到窗口,从而导致屏幕一直闪烁.我怎样才能避免它???有什么建议???这是代码的一部分.

We have multiple TVs each connected to a different computer. The goal is to display/setfocus on a continuous loop cycling through two applications. This has to be synchronized across all TVs. Originally i had set it up cycle through all the apps in the task bar by sending the alt+esc key. Which worked fine but had a hard time synchronizing it across all TVs. So i used the AppActivate to setfocus and switch between windows based on even/odd minute. It is now synchronized, but the screen seems to try to setfocus to the window every second therby causing the screen to flicker all the time. How can i avoid it??? Any suggestions??? Here is the part of the code.

' Loop lasts 1 second

intSleep = 1000

Set wshShell = CreateObject("WScript.Shell")

'repeat process indefinetly

Do while infiniteloop=0
    a = minute(time())
    intResult = a Mod 2  ' to check for even/odd minute

    If intResult = 0 Then
        'display window1
       if wshShell.AppActivate "Display - [Dashboard]" = false then
            wshShell.AppActivate "Display - [Dashboard]"
       end if

    ElseIf intResult = 1 Then
        'display window2
        if wshShell.AppActivate "Display - [TEST]" = false then
            wshShell.AppActivate "Display - [TEST]" 
       end if

    End If
    Wscript.Sleep intSleep

Loop

推荐答案

它每秒闪烁一次,因为变量 intResult 在整个偶数分钟内等于 0.您需要的是另一个变量,例如 "intLastResult".

It flickers every second because the variable intResult equals 0 for the entire even minute. What you need is another variable, like "intLastResult".

在循环结束时,您将设置 intLastResult=intResult,并重新执行 IF 语句以更改焦点,以便它们仅在当前结果与先前结果不同时执行.

At the end of your loop, you would set intLastResult=intResult, and re-do your IF statements for changing focus so they only execute when the current result differs from the previous result.

I.E.如果 intResult=0 AND intLastResult=1 Then"或If intResult=1 AND intLastResult=0 Then"

这样他们每分钟应该只开火一次.

This way they should only fire once per minute.

这篇关于VBScript - 使用 AppActivate 将焦点切换到窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆