gpt4 book ai didi

C# 将控制台应用程序挂接到记事本

转载 作者:太空狗 更新时间:2023-10-29 20:30:48 25 4
gpt4 key购买 nike

我想做的是创建一个简单的 Windows 应用程序,它将自身挂接到记事本上,然后模拟击键。我有打开记事本,把它带到前台,然后模拟数字1被按下的过程。但是,如果我点击记事本,事件的内容就会变成正在输入的内容。

如何将此应用程序绑定(bind)到记事本,以便我可以单击并输入任何内容,并且此应用程序仍会将命令推送到记事本?

This is the DLL i'm using to simulate keypressing :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Diagnostics;
using WindowsInput;

namespace NotePadTesting
{
class Program
{
[DllImport("USER32.DLL", CharSet = CharSet.Unicode)]
public static extern IntPtr FindWindow(string lpClassName,
string lpWindowName);
// Activate an application window.
[DllImport("USER32.DLL")]
public static extern bool SetForegroundWindow(IntPtr hWnd);


static void Main(string[] args)
{

Process[] processes = Process.GetProcessesByName("notepad");

if (processes.Length == 0)
{

Process.Start("notepad.exe");
processes = Process.GetProcessesByName("notepad");

}
if (processes.Length == 0)
{
throw new Exception("Could not find notepad huh....");
}

IntPtr WindowHandle = processes[0].MainWindowHandle;
SetForegroundWindow(WindowHandle);

for (int i = 0; i < 500; i++)
{
System.Threading.Thread.Sleep(100);
InputSimulator.SimulateKeyPress(VirtualKeyCode.VK_1);

}


}
}
}

最佳答案

如果您已经有了要输入的窗口的句柄,您可以使用 PostMessage功能。您只需用谷歌搜索虚拟键码。

关于C# 将控制台应用程序挂接到记事本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20747497/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com