Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write a program that can interact with other programs

Tags:

java

I want to write a program that could play solitaire on windows. The user would run the program and open solitaire and watch as the cards move. Its easy to write the AI for the program that would play solitaire (I obviously don't have the source code for the Windows solitaire). One way I can think of doing this is if I took an image of the solitaire and analyzed it to determine the current state of the cards, then I could pass the current state of the cards to my program, which could determine the next move. But how would I execute the clicking command.

More generally, I want to write a program that can interact with another program like a user would. I have experience with C, C++, Java, Ruby. But I don't know how to even get started on this, or whether this can be even done?

like image 970
Spart Avatar asked Oct 30 '11 14:10

Spart


2 Answers

I'm not sure about all the other posts here, but Java has a Robot class that allows you to (easily) dispatch keyboard and mouse events to the underlying OS (windows in this case) that would allow you to do exactly what you're talking about. It's a little class I've used loads of times to "automate" tasks on windows.

(I know this is an old thread, but in case anyone else out there in the world stumbles upon it like I have and want to do what you've outlined.)

like image 70
jaime Avatar answered Sep 28 '22 19:09

jaime


If you want to automate Windows tasks, then use a language specifically written to perform this. Ones that come to mind include WinBatch, AutoIt, and AutoHotkey.

like image 34
Hovercraft Full Of Eels Avatar answered Sep 28 '22 19:09

Hovercraft Full Of Eels