Java.awt.Robot not working on Android emulator running on PC -
i have written java program using java.awt.robot
try play video game me. game called magic tiles 3, , it's similar piano tiles. in essence, goal tap black tiles once reach bottom of screen. and, since i'm lazy, decided let computer work.
i set android tablet emulator called bluestacks on windows 10 pc , loaded game onto it. ran code below try identify point mouse cursor , click. code searches black tiles , uses robot click on them.
when run code, can see robot moving mouse cursor onto tiles, , can see left-clicking correctly (i opened black background in paint, chose orange paintbrush, , made orange dots tiles should be). can verify left-clicking on tiles mouse works properly. however, reason, clicks not register correctly on android emulator. causing this?
public class main { public static void main(string[] args) throws awtexception, ioexception, interruptedexception { // todo auto-generated method stub robot perfectrunner = new robot(); rectangle screenrect = new rectangle(700, 50, 530, 950); system.out.println("hello!"); float[] leftcolor = new float[3]; float[] leftmiddlecolor = new float[3]; float[] rightmiddlecolor = new float[3]; float[] rightcolor = new float[3]; while(true) { perfectrunner.getpixelcolor(755, 800).getrgbcolorcomponents(leftcolor); perfectrunner.getpixelcolor(900, 800).getrgbcolorcomponents(leftmiddlecolor); perfectrunner.getpixelcolor(1044, 800).getrgbcolorcomponents(rightmiddlecolor); perfectrunner.getpixelcolor(1169, 800).getrgbcolorcomponents(rightcolor); if (istile(leftcolor)) { perfectrunner.mousemove(755, 850); perfectrunner.mousepress(inputevent.button1_down_mask); thread.sleep(100l); perfectrunner.mouserelease(inputevent.button1_down_mask); } if (istile(leftmiddlecolor)) { perfectrunner.mousemove(900, 850); perfectrunner.mousepress(inputevent.button1_down_mask); thread.sleep(100l); perfectrunner.mouserelease(inputevent.button1_down_mask); } if (istile(rightmiddlecolor)) { perfectrunner.mousemove(1044, 850); perfectrunner.mousepress(inputevent.button1_down_mask); thread.sleep(100l); perfectrunner.mouserelease(inputevent.button1_down_mask); } if (istile(rightcolor)) { perfectrunner.mousemove(1169, 850); perfectrunner.mousepress(inputevent.button1_down_mask); thread.sleep(100l); } } } public static boolean istile (float[] color) { if (color[0] < 0.1 && color[1] < 0.1 && color[2] < 0.1) { return true; } return false; } }
Comments
Post a Comment