将输入输入到流程中
在通过雅虎通与朋友交谈时,我告诉他,如果有人开始对话时制作一个机器人来回答通用消息,那真是太酷了。想到我告诉他的话,我意识到做这样的事情会很有趣。问题是我对win32了解不多。
所以我的问题是:如何将一个进程“链接”到另一个进程和 Windows 环境?目标是让一个应用程序在后台运行,它会进行某种查询以查看打开了哪些窗口,并且当出现新的 yahoo Messenger 对话窗口时,它应该向该窗口发送击键事件列表。
我可以使用 C# 或 VC++ 进行编程部分,并且我可以使用任何帮助:可以帮助我的具体答案或提示 - 例如:要谷歌搜索什么。到目前为止,我的谷歌研究只提供了一些可以为您执行此操作的应用程序/dll/代码以及一些脚本内容,而我并没有完全搜索这些内容。我想自己完成所有工作,这样我就可以从中学习。
While talking with a friend over yahoo messenger, I told him would be really cool to make a bot to answer with generic messages when someone starts a conversation. Upon thinking about what I told him, I realized it would be quite interesting to do something like that. The problem is that I don't know much about win32.
So my question is this: how do you 'link' a process to both another one and the windows environment? The goal would be to have an application running in the background which makes some sort of a query to see what windows are opened and when a new yahoo messenger conversation window appears it should send a list of keystroke events to that window.
I could use either C# or VC++ for the programming part and I can use any help: either specific answers or tips that could help me - e.g.: what to google for. So far my google research only came up with some apps/dlls/code that do that for you and some scripting stuff and I'm not exactly searching for that. I want to do all the work myself so I can learn from it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
看起来你基本上想控制其他应用程序。
在 Windows 上大约有 2 种方法可以执行此操作
1 - 使用低级 Windows API 在目标应用程序中盲目触发键盘和鼠标事件。
其基本工作方式是使用 Win32
SendInput
方法,但是您还需要做大量其他工作来查找窗口句柄等2 - 使用更高级别的 UI 自动化 API 以更结构化的方式与应用程序交互。
最好的(好吧,无论如何,最新的)方法是使用 Windows Vista 和 7 中附带的 Microsoft UI Automation API(在 XP 上也可用)。 这是它的 MSDN 起始页。
我们使用 microsoft UI 自动化 API我的工作是对我们的应用程序进行自动化 UI 测试,这还不错。但请注意,无论您选择如何解决这个问题,它都充满危险,并且它是否有效取决于目标应用程序。
祝你好运
It seems like you basically want to control other applications.
There are roughly 2 ways to do this on windows
1 - Use the low level windows API to blindly fire keyboard and mouse events at your target application.
The basic way this works is using the Win32
SendInput
method, but there's a ton of other work you have to do to find window handles, etc, etc2 - Use a higher level UI automation API to interact with the application in a more structured manner.
The best (well, newest anyway) way to do this is using the Microsoft UI Automation API which shipped in windows vista and 7 (it's available on XP as well). Here's the MSDN starter page for it.
We use the microsoft UI automation API at my job for automated UI testing of our apps, and it's not too bad. Beware though, that no matter how you chose to solve this problem, it is fraught with peril, and whether or not it works at all depends on the target application.
Good luck
与您正在寻找的域不完全相同,但是本系列博客文章将告诉您需要了解的内容(以及其他一些很酷的东西)。
http://www.codingthewheel.com/archives/how -i-built-a-working-poker-bot
Not quite the same domain as what you're looking for, BUT this series of blog posts will tell you what you need to know (and some other cool stuff).
http://www.codingthewheel.com/archives/how-i-built-a-working-poker-bot
如果您真的想从头开始学习所有内容,那么您应该使用 C++ 和本机 WIN32 API 函数。
如果您想尝试一下 C#,那么您应该查看 pinvoke.net 网站和 托管 Windows API 项目。
您肯定需要的是 Spy++工具。
If you really want to learn everything from scratch, then you should use C++ and native WIN32 API functions.
If you want to play a bit with C#, then you should look the pinvoke.net site and Managed Windows API project.
What you'll surely need is the Spy++ tool.
http://pinvoke.net/ 似乎是您正在寻找的网站。该站点解释了如何以高级语言使用 Windows API 函数。在 pinvoke 上搜索我在下面列出的任何函数,它会为您提供能够在应用程序中使用这些函数所需的代码。
您可能需要使用 FindWindow 函数来查找您感兴趣的窗口。
您需要进程 ID,因此请使用 GetWindowThreadProcessId 抓住它。
接下来,您需要使用 OpenProcess 允许读取进程的内存。
之后,您将需要使用 ReadProcessMemory 读入进程的内存以查看它发生了什么。
最后,您需要使用 PostMessage< /a> 函数将按键发送到窗口句柄。
欢迎来到 Windows API 编程的奇妙世界。
http://pinvoke.net/ seems to be the website you are looking for. The site explains how to use Windows API functions in higher level languages. Search on pinvoke for any of the functions I've listed below and it gives you the code necessary to be able to use these functions in your application.
You'll likely want to use the FindWindow function to find the window in which you're interested.
You'll need the process ID, so use GetWindowThreadProcessId to grab it.
Next, you'll need to use OpenProcess allow for reading of the process's memory.
Afterwards, you'll want to use ReadProcessMemory to read into the process's memory to see what happening with it.
Lastly, you'll want to use the PostMessage function to send key presses to the window handle.
Welcome to the wonderful world of Windows API programming.
查看自动热键。这是做你想做的事的最快方法。
Check out Autohotkey. This is the fastest way to do what you want.