Sunteți pe pagina 1din 3

import java.awt.event.

*;
import java.awt.event.KeyEvent;
import java.awt.AWTException;
import java.awt.Robot;
import processing.serial.*;
Serial myPort;
Robot robot;
void setup() {
myPort = new Serial(this, "COM4", 9600);


size(400, 400);
try {
robot = new Robot();
}
catch (AWTException e) {
e.printStackTrace();
}
robot.mouseMove(width/2, height/2);

}
void draw() {
if(myPort.available()>0)
{
char rx = myPort.readChar();
println(rx);
if(rx =='X') test1();
if(rx =='Y') test2();
if(rx =='Z') test3();

}

}
void test1()
{
robot.mouseMove(300, 40);
delay(1000);
robot.mousePress(InputEvent.BUTTON1_MASK);
delay(10);
robot.mousePress(InputEvent.BUTTON1_MASK);
delay(10);
robot.mousePress(InputEvent.BUTTON1_MASK);
delay(10);
String[] webs = {"www.facebook.com/Yilan.Heyi","www.books.com.tw/",
"www.google.com","www.facebook.com","tw.yahoo.com","http://www.ptt.cc/index.ht
ml",
"www06.eyny.com","www.mobile01.com","http://hypesphere.com/?p=31360","http://www
.ptt.cc/bbs/Gossiping/M.1400864844.A.C76.html",
"http://forgetfulbc.blogspot.com/2014/05/mercy.html","http://54.sp88.tw/read.php
?po_sn=4702"};

int index = int(random(webs.length));
type(webs[index]);
robot.keyPress(KeyEvent.VK_ENTER);
delay(10000);
}
void test2()
{
robot.mouseMove(300, 40);
delay(1000);
robot.mousePress(InputEvent.BUTTON1_MASK);
delay(10);
robot.mousePress(InputEvent.BUTTON1_MASK);
delay(10);
robot.mousePress(InputEvent.BUTTON1_MASK);
delay(10);


String[] webs = {"www.facebook.com/Yilan.Heyi","www.books.com.tw/","flog.cc/mag
/",
"www.world.yam.com/","www.thinkingtaiwan.com/","hypesphere.com/","indot.pixnet.
net/blog/post/99298701",
"www.businesstoday.com.tw/masterpage-content","ditldesign.squarespace.com/news/
uxsystem-organization","www.google.com","www.facebook.com","www.taiwancon.com"};


int index = int(random(webs.length));
type(webs[index]);
robot.keyPress(KeyEvent.VK_ENTER);
delay(10000);
}
void test3()
{
robot.mouseMove(300, 40);
delay(1000);
robot.mousePress(InputEvent.BUTTON1_MASK);
delay(10);
robot.mousePress(InputEvent.BUTTON1_MASK);
delay(10);
robot.mousePress(InputEvent.BUTTON1_MASK);
delay(10);
String[] webs = {"technews.tw/2014/05/09/this-arcade-machine-runs-on-empty-pl
astic-bottles/","tw.gigacircle.com/102580-1","www.thenewslens.com/post/38881/","
www.juksy.com/archives/32448"
,"techorange.com/2014/05/05/writing-can-make-you-better-programmer/","www.thene
wslens.com/post/40769/","world.yam.com/post.php?id=1868","pansci.tw/archives/584
28","pansci.tw/archives/60081",
"share.inside.com.tw/posts/4574","case.ntu.edu.tw/blog/?p=17377","world.yam.com
/post.php?id=1813"};

int index = int(random(webs.length));
type(webs[index]);
robot.keyPress(KeyEvent.VK_ENTER);
delay(10000);
}
void type(int i)
{
robot.delay(4);
robot.keyPress(i);
robot.keyRelease(i);
}
void type(String s)
{
try {
println(millis());
byte[] bytes = s.getBytes();
for (byte b : bytes)
{
int code = b;
// keycode only handles [A-Z] (which is ASCII decimal [65-90])
if (code > 96 && code < 123) code = code - 32;
robot.delay(40);
robot.keyPress(code);
robot.keyRelease(code);
}
}
catch(Exception e)
{

println("error:"+e);
}
}

S-ar putea să vă placă și