2017-04-24 46 views
0

我的要求是自動切換Internet Explorer的多個選項卡。縱觀網絡和計算器後,我提到this來一個解決方案.vbs文件作爲 -SendKey到特定應用程序

Set WshShell = WScript.CreateObject("WScript.Shell") 
while 1 
    WshShell.AppActivate "Internet Explorer" 
    WScript.Sleep 7000 
    WshShell.SendKeys("^{TAB}") 
wend 

但是這種方法的問題是它發送鍵,所有活動的應用程序。 我需要它來觸發只有Internet Explorer的密鑰。 請幫忙。 在此先感謝。

回答

0

沒問題。我能夠使用C#腳本實現此目的 -

using System; 
using System.Diagnostics; 
using System.Linq; 
using System.Runtime.InteropServices; 
using System.Threading; 
using System.Windows.Forms; 

namespace SendKeyAppDemo 
{ 
    class Program 
    { 
     [DllImport("User32.dll")] 
     private static extern int SetForegroundWindow(IntPtr ptr); 
     static void Main(string[] args) 
     { 
      Process p = Process.GetProcessesByName("iexplore").FirstOrDefault(); 
      if (p.ProcessName == "iexplore") 
      { 
       while (true) 
       { 
        IntPtr h = p.MainWindowHandle; 
        SetForegroundWindow(h); 
        SendKeys.SendWait("^{TAB}"); 
        Thread.Sleep(5000); 
       } 

      } 
     } 
    } 
} 
相關問題