5

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

' 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
4

2 回答 2

3

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

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

IE"If intResult=0 AND intLastResult=1 Then" or "If intResult=1 AND intLastResult=0 Then"

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

于 2013-12-20T19:06:57.207 回答
2

使用 VBScript 并没有真正优雅的方法来执行此操作,但您可以远离 SendKeys。

我会简单地将睡眠时间增加到 1 分钟。这样,您就可以最大限度地减少它评估 If 语句的次数(从而提高性能)。它每分钟只试图窃取一次焦点:

Option Explicit

Dim shl

Set shl = CreateObject("WScript.Shell")

Do
  If (Minute(Time()) Mod 2) = 0 Then
    shl.AppActivate "Program One"
  Else
    shl.AppActivate "Program Two"
  End If

  WScript.Sleep (1000 * 60)
Loop
于 2013-10-15T16:30:08.020 回答