Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 发送特定应用程序的密钥_Windows_Batch File_Browser_Scheduled Tasks_Monitoring - Fatal编程技术网

Windows 发送特定应用程序的密钥

Windows 发送特定应用程序的密钥,windows,batch-file,browser,scheduled-tasks,monitoring,Windows,Batch File,Browser,Scheduled Tasks,Monitoring,我的要求是自动切换Internet Explorer的多个选项卡。在浏览了web和stackoverflow之后,我将附带的解决方案.vbs文件称为- Set WshShell = WScript.CreateObject("WScript.Shell") while 1 WshShell.AppActivate "Internet Explorer" WScript.Sleep 7000 WshShell.SendKeys("^{TAB}") wend 但是这种方法的

我的要求是自动切换Internet Explorer的多个选项卡。在浏览了web和stackoverflow之后,我将附带的解决方案.vbs文件称为-

Set WshShell = WScript.CreateObject("WScript.Shell")
while 1
    WshShell.AppActivate "Internet Explorer"
    WScript.Sleep 7000
    WshShell.SendKeys("^{TAB}")
wend
但是这种方法的问题是它将密钥发送给所有活动的应用程序。 我需要它来触发Internet Explorer的密钥。 请帮忙。 提前谢谢。

没问题。 我可以使用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);
                }

            }
        }
    }
}