- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我想做的是创建一个简单的 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/
我在从 python 调用共享 c 库时遇到问题。库加载正常,公开的 3 个函数之一是可调用的,并且按预期工作;但是,当向库中添加另一个函数时,我发现其他两个不起作用。发生的事情是 python 卡在
我在使用 ImageIcon().GetImage() 时遇到问题 奇怪的是,它有时可以工作并向我显示带有 map 的窗口,而有时却不能。它也可以在其他计算机上完美运行,但不能在我的计算机上运行! 我
我们有时会遇到一个问题,即我们在 IIS 中有许多具有以下状态的请求:RequestAcquireState。 我们正在使用 SqlSessionStateStore 来管理 session 。当我们
我有一个 MobileSubstrate 插件,可以挂接跳板(不在实际的 objective-c 代码中,而是在 plist 中)。它包含一个 UIWebView,它加载一个 NSURLRequest
我正在尝试使用 Django 1.7,并按照说明进行操作 here .不幸的是,该过程似乎因以下输出而挂起: [Watt] ~/Projects/proj/proj master > python p
我正在使用 HDP 2.3.0.0-2557,我正在尝试运行如下所示的配置单元查询: beeline> !connect jdbc:hive2://localhost:10000 Connecting
我正在尝试使用 mxnet 设置 AWS Greengrass,以便在 Raspberry Pi 上进行机器学习。 当从 https://docs.aws.amazon.com/greengrass/
我是一名优秀的程序员,十分优秀!