本帖最后由 mimiwuqi 于 2026-2-27 14:49 编辑
[C#] 纯文本查看 复制代码 using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading;
class Program
{
[DllImport("user32.dll")]
static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
const uint WM_CHAR = 0x0102;
static void Main()
{
Process.Start("notepad.exe");
Thread.Sleep(2000);
IntPtr targetHwnd = GetForegroundWindow();
string text = "username";
foreach (char c in text)
{
SendMessage(targetHwnd, WM_CHAR, (IntPtr)c, IntPtr.Zero);
Thread.Sleep(50);
}
}
} |