【发布时间】:2012-01-26 04:04:18
【问题描述】:
我正在尝试编写一个程序,该程序将获取一行数据并将其传递到另一个窗口/进程。
这是我到目前为止的代码,但我无法弄清楚如何将键盘命令发送到 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是您正在寻找的。也许您的问题已经在这里解决了:stackoverflow.com/questions/523405/…
标签: c# command keyboard-events