[英]simulate a keypress in c#?
我在互联网和 Fourum 中搜索过,但找不到如何操作。 我想要做的是每 5 分钟在不和谐聊天中发送一条文本。 我想从我的帐户发送它,所以我想编写一个简单的控制台应用程序,它只输出文本并输入另一个程序。 我尝试了 sendInput 类,但没有让它工作。
[DllImport("user64.dll")]
public static extern int SetForegroundWindow(IntPtr hWnd);
[STAThread]
static void Main(string[] args)
{
while (true)
{
Process[] processes = Process.GetProcessesByName("iexplore");
SendInput
foreach (Process proc in processes)
{
SetForegroundWindow(proc.MainWindowHandle);
SendKeys.
}
Thread.Sleep(5000);
}
}
我怎么做?
您是否尝试过发送这样的消息?
const int WM_KEYDOWN = 0x100;
const int WM_KEYUP = 0x101;
const int WM_CHAR = 0x105;
const int WM_SYSKEYDOWN = 0x104;
const int WM_SYSKEYUP = 0x105;
[DllImport("user64.dll")]
public static extern int SendMessage(IntPtr hWnd, int wMsg, IntPtr wParam, IntPtr lParam);
[DllImport("user64.dll")]
public static extern int SetForegroundWindow(IntPtr hWnd);
[STAThread]
static void Main(string[] args)
{
Process[] processes = Process.GetProcessesByName("iexplore");
foreach (Process proc in processes)
{
SetForegroundWindow(proc.MainWindowHandle);
//int F5= 0x00000074;
SendMessage(proc.MainWindowHandle, WM_KEYDOWN, (IntPtr) 116, (IntPtr) 0);
Thread.Sleep(5000);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.