0

How do I exactly make a C++ program interact with another program and interact with something I have clicked on.

Example: If I wanted to make an MSN auto reply program and I would have a dialog box that would ask me what I would want to type and than the program would paste that into the MSN chat box.

5
  • FYI, there's an MSN extension which already supports auto-reply: msgplus.net Maybe you could ask on the forums there? Commented Aug 8, 2011 at 5:15
  • It's not really about making a msn Extension. I am just asking how to make C++ interact with x program. Commented Aug 8, 2011 at 5:16
  • My comment wasn't really about making an MSN extension either. I'm just saying, it's a piece of freeware with that sort of interaction already written. For example, here's an auto answer script for MsgPlus: msghelp.net/showthread.php?tid=94948&pid=997399#pid997399 You can see there the usage of user32.dll for finding window handles and mapping keystrokes (Which is probably how you'll be doing it in C++, too). Commented Aug 8, 2011 at 5:24
  • 1
    Also, if you mean X as in X11 please tag the question, I assumed from your comment about MSN that it was a Windows-only question. Commented Aug 8, 2011 at 5:24
  • Duplicate of Is it possible to programmatically click button of another app in Linux? Commented Aug 8, 2011 at 15:55

1 Answer 1

1

It turns out that X by itself doesn't let you do this, but you can make it possible by installing the Xtest extensions (and then reading about them...)

Other approaches would be to inject events at the operating system keyboard/mouse level or using some existing or patched in interface of the target program. A lot of unix-ish tools can be set up to accept command input on stdin or accomplish a lot via command line options for scripting purposes.

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

3 Comments

"X by itself doesn't let you do this": actually it does. You'll have to use the disgusting XLib (or the slightly less disgusting xcb) but the point is that you can query the window list and send events to windows. I can't post an accurate answer since I'm just beginning to look at XLib for now, but I'm pretty sure it can be done. The problem is that you'll have a hard time figuring out what is a button and what is not.
@Alexandre C. I'd be quite interested in example code that simply delivered a fixed location mouse click or key event to another process's window, as this would be contrary to everything I found in past research on the subject.
@Chris: Let me favorite this, and I'll go back to you as soon as my research on the subject advances. For now, I'll just point you to the XSendEvent function, which seems relevant here. If this weren't possible, window manager writers would have a hard time doing their job.

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.