package backStage;
import java.awt.AWTException;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.io.IOException;
public class RobotBox {
private static final int RATIOMODE=1; //比例模式
private static final int TOUCHMODE=2; //触摸板模式
private Mouse_move mouse=null;
private int nowMode=0;
private String textClipBoard;
private int PCwidth,PCheight;
public RobotBox(){
Toolkit tl =Toolkit.getDefaultToolkit();
Dimension screenSize = tl.getScreenSize();
PCwidth = (int )screenSize.getWidth();
PCheight = (int )screenSize.getHeight();
}
//创建机器人盒子
public boolean foundRobotBox(int mode) {
if(mode==RATIOMODE){
try {
mouse =new RatioMode(PCwidth,PCheight);
nowMode=RATIOMODE;
return true;
} catch (AWTException e) {
e.printStackTrace();
return false;
}
}else{
try {
mouse =new TouchMode(PCwidth, PCheight);
nowMode=TOUCHMODE;
return true;
} catch (AWTException e) {
e.printStackTrace();
return false;
}
}
}
//设置模式
public boolean setMode(int mode){
if(mode==RATIOMODE){
try {
mouse =new RatioMode(PCwidth, PCheight);
nowMode=RATIOMODE;
return true;
} catch (AWTException e) {
e.printStackTrace();
return false;
}
}else{
try {
mouse =new TouchMode(PCwidth, PCheight);
nowMode=TOUCHMODE;
return true;
} catch (AWTException e) {
e.printStackTrace();
return false;
}
}
}
//获取当前模式
public int getMode(){
return nowMode;
}
//取得当前PC分辨率
public String getCorrd(){
return PCwidth+"X"+PCheight;
}
//分辨率或比例 数字入口
public void setRatio(int length, int wide){
mouse.setRatio(length, wide);
}
//为剪切板载入字符串
public void setClipBoard(String str){
textClipBoard=str;
String vc = str.trim();
StringSelection ss = new StringSelection(vc);
Clipboard sysClb=null;
sysClb = Toolkit.getDefaultToolkit().getSystemClipboard();
sysClb.setContents(ss,null);
}
//取得当前剪切板的内容
public String getClipBoard(){
return textClipBoard;
}
//执行粘贴操作
public void toPaste(){
mouse.pressKey(KeyEvent.VK_CONTROL);
mouse.pressKey(KeyEvent.VK_V);
mouse.releaseKey(KeyEvent.VK_CONTROL);
mouse.releaseKey(KeyEvent.VK_V);
}
//执行关机操作
public boolean toShutdown(){
try {
Runtime .getRuntime().exec("shutdown.exe -s -t 5");
return true;
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
//执行定时关机
public boolean toShutdown(int time){
String orderStr="shutdown.exe -s -t";
orderStr = orderStr +" "+time;
try {
Runtime .getRuntime().exec(orderStr);
return true;
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
//单击鼠标左键
public void click_LeftMouseKey(){
mouse.pressMouseKey(InputEvent.BUTTON1_MASK);
mouse.releaseMouseKey(InputEvent.BUTTON1_MASK);
}
//单击鼠标右键
public void click_RightMouseKey(){
mouse.pressMouseKey(InputEvent.BUTTON2_MASK);
mouse.releaseMouseKey(InputEvent.BUTTON2_MASK);
}
//长按鼠标左键
public void onClick_LeftMouseKey(){
mouse.pressMouseKey(InputEvent.BUTTON1_MASK);
}
//长按鼠标右键
public void onClick_RightMouseKey(){
mouse.pressMouseKey(InputEvent.BUTTON2_MASK);
}
//释放鼠标左键
public void release_LeftMouseKey(){
mouse.releaseMouseKey(InputEvent.BUTTON1_MASK);
}
//释放鼠标右键
public void release_RightMouseKey(){
mouse.releaseMouseKey(InputEvent.BUTTON2_MASK);
}
//向上滑动滚轮
public void WheelmouseUp(){
mouse.Wheelmouse(-1);
}
//向上滑动滚轮
public void WheelmouseDown(){
mouse.Wheelmouse(1);
}
//提高音量
public void setHighSound(){
}
//降低音量
public void setLowSound(){
}
//读取当前系统音量(待考虑)
public int getSystemSound(){
return 0;
}
}