I have another window open with another program that responds when specific keys are being pressed I will call this program1.
I am now testing it with the program at the end of the message I will call this program2, the program2 code is supposed to press the keys that program 1 responds to with specific cues.
It should press w, s, a
, and d in random order. and it should press either up, left, down, or right depending on which side of gx,gy
an object with the RGB color (255,106,100) is.
Program2 also streams what is on my screen, so it can see the color. (I know some variables are useless. I was just too lazy to delete them if I found out I didn't use them, you only have to point this out if it is what causes the problem)
The code:
int x=1;
int y=0;
int gxbeta=0;
int gybeta=0;
int gx;
int gy;
int targetx=0;
int targety=0;
int i;
int h;
int dice=0;
color z=color(76,140,90);
color team= color(255,106,100);
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
import java.awt.Rectangle;
Robot robot;
void setup(){
size(1920, 1080);
//Let's get a Robot...
try {
robot = new Robot();
} catch (AWTException e) {
e.printStackTrace();
println(e.getMessage());
exit();
}}
void draw(){
background(0);
Rectangle r = new Rectangle(0, 0, width, height);
BufferedImage img1 = robot.createScreenCapture(r);
PImage img2 = new PImage(img1);
image(img2, 0, 0);
//Zoek de kleur met de nieuwe get
y++;
if(y==height){
y=0;
}
if(y==0){
x=x+1;
}
color colorFromget= get(gxbeta,gybeta);
color colorFromGet = get(x,y);
if(colorFromGet == team){targetx=x;
targety=y;}
if(z==colorFromget){gx=gxbeta; gy=gybeta;}
//Kijk of hij in range van een kant is en schiet
if ((targetx<gy)&&(targety < (gy + 38)) && (targetx > (gy - 38))){
robot.keyPress(KeyEvent.VK_LEFT);
delay(10000);
robot.keyRelease(KeyEvent.VK_LEFT);}
//Etc
ellipse(gx, gy, 25, 25);
//loop een random kant op en laat dan de key los
dice=random(0.3);
if(dice==0){robot.keyPress(KeyEvent.VK_W);
delay(10000);
robot.keyRelease(KeyEvent.VK_W);}
if(dice==0.1){robot.keyPress(KeyEvent.VK_A);
delay(10000);
robot.keyRelease(KeyEvent.VK_A);}
if(dice==0.2){robot.keyPress(KeyEvent.VK_S);
delay(10000);
robot.keyRelease(KeyEvent.VK_S);}
if(dice==0.3){robot.keyPress(KeyEvent.VK_D);
delay(10000);
robot.keyRelease(KeyEvent.VK_D);}
}