相关疑难解决方法(0)

c#将键盘命令发送到另一个窗口/进程

我正在尝试编写一个程序,它将获取一行数据并将其传递到另一个窗口/进程.

这是我到目前为止的代码,但我还没有弄清楚如何将键盘命令发送到OUTLOOK进程.

我希望能够使用Tab命令/键和Enter命令/键.

这是我到目前为止所尝试的

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Threading;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Windows.Forms;

namespace Config
{
    class Program
    {
        [STAThread]
        static void Main(string[] args)
        {
            System.Threading.Thread.Sleep(30);//300000
            TextReader tr = new StreamReader("config.txt");
            Clipboard.SetText(tr.ReadLine());
            tr.Close();

            var proc = Process.GetProcessesByName("OUTLOOK").FirstOrDefault();
            if (proc != null && proc.MainWindowHandle != IntPtr.Zero)
            {
                SetForegroundWindow(proc.MainWindowHandle);
                //SendKeys.Send("{ENTER}");
                //   Clipboard.GetText();
            }
        }

        [DllImport("user32")]
        private static extern bool SetForegroundWindow(IntPtr hwnd);
    }
}
Run Code Online (Sandbox Code Playgroud)

c# command keyboard-events

12
推荐指数
4
解决办法
6万
查看次数

标签 统计

c# ×1

command ×1

keyboard-events ×1