Reputation: 127
I have a general question :
If I got a GUI (e.g. metaTrader => online broker), is it possible to read data from this GUI using java?
My idea:
Using the java.awt.robot and do something like:
package java_robot;
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
import java.awt.event.InputEvent;
import java.awt.event.MouseEvent;
public class java_robot {
public static void main(String[] args) {
try {
// create class
Robot robot = new Robot();
// wait 1 sec
robot.delay(1000);
// move mouse to wanted area
robot.mouseMove(x, y);
}
// mark an area, copy it and save in file..
} catch (AWTException e) {
e.printStackTrace();
}
}
}
Is this idea good, or do you know other solution´s to read data from a GUI? (working on mac)
Upvotes: 0
Views: 167
Reputation: 43023
You can use the Robot#createScreenCapture()
method here.
Robot r = new Robot();
// Capture area
int width = ...
int height = ...
Rectangle area = new Rectangle(width, height);
BufferedImage image = r.createScreenCapture(area);
// Save to file
ImageIO.write(image, "png", new File("/screenshot.png"));
Alternatively, if metaTrader loads its data from internet, you can sniffe its traffic and determine how and where its data comes. Then you could try to mimic its internet calls and get the data yourself as long as it is not ciphered.
You could also build a proxy in Java and ask metaTrader to use this proxy. All data requested by metaTrader would go through your proxy. This can give you a chance to read the data... again as long as it is not ciphered.
The image below illustrates how things work. Alice plays the role of meaTrader. Bob is the source of data of metaTrader. Proxy is your Java app.
You can find a simple implementation of such a proxy here: http://www.java2s.com/Code/Java/Network-Protocol/Asimpleproxyserver.htm.
References:
Upvotes: 1