RE: Poste dein STRG-V
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.*;
import ipcapture.*;
import hypermedia.net.*;
UDP udp;
int targetX;
int targetY;
String strTargetx;
String strTargety;
Robot catchMouse;
IPCapture cam;
PImage keyW;
PImage keyWg;
PImage keyA;
PImage keyAg;
PImage keyS;
PImage keySg;
PImage keyD;
PImage keyDg;
PImage keyL;
PImage keyLg;
PImage keyQ;
PImage keyQg;
PImage keyC;
PImage keyCg;
PImage keyH;
PImage keyHg;
PImage key1;
PImage key1g;
int keyWpress = 0;
int keySpress = 0;
int keyApress = 0;
int keyDpress = 0;
int keyHpress = 0;
int Licht;
int Servo1Pos;
int Servo2Pos;
int Servo1PosRund;
int Servo2PosRund;
int fensterX;
int fensterY;
int MousePosX;
int MousePosY;
int setMousePosXmin;
int setMousePosYmin;
int setMousePosXmax;
int setMousePosYmax;
int CurserAn;
int Taste1 = 0;
String ip = "192.168.178.40";
int port = 8888;
int acknowledged = 1;
int MotorSpeed = 0;
String strMotor;
void setup() {
background(51);
size(1480, 920);
udp = new UDP( this, 6000 );
udp.listen( true );
noCursor();
cam = new IPCapture(this, "http://192.168.178.21:8080/video", "", "");
cam.start();
cursor(CROSS);
keyW = loadImage("keyW.png");
keyWg = loadImage("keyWg.png");
keyA = loadImage("keyA.png");
keyAg = loadImage("keyAg.png");
keyS = loadImage("keyS.png");
keySg = loadImage("keySg.png");
keyD = loadImage("keyD.png");
keyDg = loadImage("keyDg.png");
keyL = loadImage("keyL.png");
keyLg = loadImage("keyLg.png");
keyQ = loadImage("keyQ.png");
keyQg = loadImage("keyQg.png");
keyC = loadImage("keyC.png");
keyCg = loadImage("keyCg.png");
keyH = loadImage("keyH.png");
keyHg = loadImage("keyHg.png");
key1 = loadImage("key1.png");
key1g = loadImage("key1g.png");
image(keyW, 200, 700);
image(keyA, 120, 800);
image(keyS, 225, 800);
image(keyD, 330, 800);
image(keyL, 500, 800);
image(keyH, 605, 800);
image(keyC, 710, 800);
image(key1, 890, 800);
try
{
catchMouse = new Robot();
}
catch (AWTException e)
{
println("Die Robot-Klasse funktionert auf deinem System leider nicht!");
exit();
}
textSize(24);
fill(0, 102, 153);
text("Licht", 515, 800);
text("Sirene", 615, 800);
text("Curser", 720, 800);
textSize(20);
text("Sentry Modus", 880, 798);
addMouseWheelListener(new MouseWheelListener() {
public void mouseWheelMoved(MouseWheelEvent mwe) {
mouseWheel(mwe.getWheelRotation());
}
}
);
fill(255);
stroke(51);
rect(500, 300, 480, 320);
fill(153);
stroke(51);
rect(45, 640, 20, 255);
}
void mouseWheel(int MausRad) {
fill(153);
rect(45, 640, 20, 255);
MausRad *= -5;
MotorSpeed += MausRad;
if(MotorSpeed < 0) {
MotorSpeed = 0;
}
if(MotorSpeed > 255) {
MotorSpeed = 255;
}
fill(204, 102, 0);
rect(45, 895 - MotorSpeed, 20, 255);
fill(51);
stroke(51);
rect(45, 895, 20, 255);
}
void draw() {
if (Taste1 == 0) {
if ((mouseX>=500) && (mouseX<=980) && (mouseY>=300) && (mouseY<=620)) {
Servo1Pos=-500;
Servo1Pos += mouseX;
}
if ((mouseX>=500) && (mouseX<=980) && (mouseY>=300) && (mouseY<=620)) {
Servo2Pos=-300;
Servo2Pos += mouseY;
}
int Servo1PosRund = (int) (Servo1Pos / 2.66666667);
int Servo2PosRund = (int) (Servo2Pos / 1.77777778);
targetX = Servo1PosRund;
targetY = Servo2PosRund;
}
strTargetx = "000" + str(targetX);
strTargetx = strTargetx.substring(strTargetx.length()-3);
strTargety = "000" + str(targetY);
strTargety = strTargety.substring(strTargety.length()-3);
strMotor = "000" + str(MotorSpeed);
strMotor = strMotor.substring(strMotor.length()-3);
if (cam.isAvailable()) {
cam.read();
image(cam, 500, 300);
}
if(acknowledged==1){
udp.send(strTargetx + strTargety + keyWpress + keyApress + keySpress + keyDpress + keyHpress + Licht + Taste1 + strMotor, ip, port );
acknowledged = 0;
}
fensterX = frame.getLocation().x;
fensterY = frame.getLocation().y;
fensterX += 3;
fensterY += 25;
setMousePosXmax=fensterX+980;
setMousePosYmax=fensterY+620;
setMousePosXmin=fensterX+500;
setMousePosYmin=fensterY+300;
MousePosX=fensterX+mouseX;
MousePosY=fensterY+mouseY;
if(CurserAn==0) {
if (mouseX>980) {
catchMouse.mouseMove(setMousePosXmax, MousePosY);
}
if (mouseY>620) {
catchMouse.mouseMove(MousePosX, setMousePosYmax);
}
if (mouseX<500) {
catchMouse.mouseMove(setMousePosXmin, MousePosY);
}
if (mouseY<300) {
catchMouse.mouseMove(MousePosX, setMousePosYmin);
}
}
}
void receive(byte[] data, String HOST_IP, int PORT_RX){
String value=new String(data);
acknowledged = 1;
}
void keyPressed() {
if (((key=='w' || key=='W')) && (keySpress==0)) {
keyWpress = 1;
image(keyWg, 200, 700);
}
if (((key=='a' || key=='A')) && (keyDpress==0)) {
keyApress = 1;
image(keyAg, 120, 800);
}
if (((key=='s' || key=='S')) && (keyWpress==0)) {
keySpress = 1;
image(keySg, 225, 800);
}
if (((key=='d' || key=='D')) && (keyApress==0)) {
keyDpress = 1;
image(keyDg, 330, 800);
}
if ((key=='l' || key=='L')) {
Licht++;
}
if (Licht==1) {
image(keyLg, 500, 800);
}
if (Licht==2) {
Licht = 0;
image(keyL, 500, 800);
}
if ((key=='c' || key=='C')) {
CurserAn++;
}
if (CurserAn==1) {
image(keyCg, 710, 800);
}
if (CurserAn==2) {
CurserAn = 0;
image(keyC, 710, 800);
}
if ((key=='h' || key=='H')) {
keyHpress = 1;
image(keyHg, 605, 800);
}
if ((key=='1' || key=='!')) {
Taste1++;
}
if (Taste1==1) {
image(key1g, 890, 800);
}
if (Taste1==2) {
Taste1 = 0;
image(key1, 890, 800);
}
}
void keyReleased() {
if ((key=='w' || key=='W')) {
keyWpress = 0;
image(keyW, 200, 700);
}
if ((key=='a' || key=='A')) {
keyApress = 0;
image(keyA, 120, 800);
}
if ((key=='s' || key=='S')) {
keySpress = 0;
image(keyS, 225, 800);
}
if ((key=='d' || key=='D')) {
keyDpress = 0;
image(keyD, 330, 800);
}
if ((key=='h' || key=='H')) {
keyHpress = 0;
image(keyH, 605, 800);
}
}
|