0

我正在创建一个程序,通过控制台应用程序控制 excel,但我需要不断关注控制台。我已经尝试了一些方法,例如 SetForegroundWindow() ,但没有奏效。我怎样才能做到这一点?我需要它在while循环内,这样每次我插入一个字符(代码完成,所以我不必每次都按Enter键)它留在控制台应用程序中并且不会改变焦点做excel。

foreach (Process p in prcss)
        {
            p.WaitForInputIdle();
            IntPtr h = p.MainWindowHandle;
            SetForegroundWindow(h);

            if (p.ProcessName == prog || p.ProcessName == progcaps)
            {
                Console.WriteLine("\n\nProcess: {0} ID: {1}\n", p.ProcessName, p.Id); //Imprime apenas o que queremos        

            }

            string pname = p.ProcessName;

            //Enter
            SendKeys.SendWait("~");
            SendKeys.SendWait("{F2}");

            while (true)
            {
                //Code goes here
            }
       }
4

0 回答 0