0

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.

5 Answers 5

1

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, etc

2 - 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

Sign up to request clarification or add additional context in comments.

3 Comments

I'll go with the first one for the learning part. If I'll stumble upon this kind of tasks in the future, obviously I'll try not to reinvent the wheel and go for the second one. Thanks!
I noticed you've got a small number of reputation indicating you're a new user to StackOverflow. Welcome :-) If you find that any of the answers here helped you, then it's considered good practice to tick the up-arrow next to the answer, to indicate to others in future that you found it helpful. If one of the answers contained the solution you actually decided to implement, then that's what the green "accepted" tick is for. Cheers! :-)
@Orieon Edwards: it seems I still keep bumping in your kind of comments; that's a good thing, too, because I always forget about the voting system.
1

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

1 Comment

very interesting; but if you meet any FBI agents, please don't tell them I said that. Thanks!
1

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.

Comments

0

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.

2 Comments

Sounds right. Thank you, both for the tips and the warm welcome. All of the win32 API should be belong to me in no time.
I would rather just code it in C++/Win32 if you're heavily using Win32-APIs anyways.
0

Check out Autohotkey. This is the fastest way to do what you want.

1 Comment

I'm looking for the best way to do it; and the way that I can learn from the most; probably they are the same; also, as I mentioned in the question, I'm NOT looking for an app that does that for me; thanks for your answer anyway!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.