我正在尝试编写一个程序,将数据传递到另一个窗口/进程。
这是我目前的代码,但我无法弄清楚如何向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);
}
}
SendMessage
就是你要找的东西。 也许你的问题已经在这里得到解决了:https://dev59.com/LnRB5IYBdhLWcg3wxZxK - arminb