概述
public class WeChatApplication
{
public static void main(String[] args) throws ParseException, ParseException
{
System.out.println("Start Success !");
Execute execute = new Execute();
execute.everyday("李进友友哥","07:59:54","我想要8-9点的3号场地");
}
}
public class WeChatRobot
{
private Robot bot = null;
private Clipboard clip = null;
public WeChatRobot()
{
try
{
this.clip = Toolkit.getDefaultToolkit().getSystemClipboard();
this.bot = new Robot();
} catch (AWTException e) {
e.printStackTrace();
}
}
public void OpenWeChat() {
bot.keyPress(KeyEvent.VK_CONTROL);
bot.keyPress(KeyEvent.VK_ALT);
bot.keyPress(KeyEvent.VK_W);
bot.keyRelease(KeyEvent.VK_CONTROL);
bot.keyRelease(KeyEvent.VK_ALT);
bot.delay(1000);
}
public void ChooseFriends(String name) {
Transferable text = new StringSelection(name);
clip.setContents(text, null);
bot.delay(1000);
bot.keyPress(KeyEvent.VK_CONTROL);
bot.keyPress(KeyEvent.VK_F);
bot.keyRelease(KeyEvent.VK_CONTROL);
bot.delay(1000);
bot.keyPress(KeyEvent.VK_CONTROL);
bot.keyPress(KeyEvent.VK_V);
bot.keyRelease(KeyEvent.VK_CONTROL);
bot.delay(2000);
bot.keyPress(KeyEvent.VK_ENTER);
}
public void SendMessage(String message) {
Transferable text = new StringSelection(message);
clip.setContents(text, null);
bot.delay(1000);
bot.keyPress(KeyEvent.VK_CONTROL);
bot.keyPress(KeyEvent.VK_V);
bot.keyRelease(KeyEvent.VK_CONTROL);
bot.delay(1000);
bot.keyPress(KeyEvent.VK_ENTER);
bot.delay(1000);
bot.keyPress(KeyEvent.VK_CONTROL);
bot.keyPress(KeyEvent.VK_ALT);
bot.keyPress(KeyEvent.VK_W);
bot.keyRelease(KeyEvent.VK_CONTROL);
bot.keyRelease(KeyEvent.VK_ALT);
}
}
public class Execute {
private WeChatRobot robot = new WeChatRobot();
private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
public void everyday(String friendName,String timeStr,String message) throws ParseException {
//获取目标时间
Date date = getDate(timeStr);
Timer timer = new Timer();
TimerTask timerTask = new TimerTask() {
@Override
public void run() {
printLog(friendName,message);
robot.OpenWeChat();
robot.ChooseFriends(friendName);
robot.SendMessage(message);
}
};
timer.schedule(timerTask,date,1000*60*60*24);
}
private void printLog(String friendName, String message) {
System.out.println("-----------------发送消息-----------------");
System.out.println("当前时间: " + sdf.format(new Date()));
System.out.println("发送对象: " + friendName);
System.out.println("发送内容: " + message);
}
private Date getDate(String timeStr) throws ParseException {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
//获取当前日期 例如 2020-22-22
String currentDate = sdf.format(new Date());
//组拼 目标时间 2020-22-22 22:22:22
String targetTime = currentDate+" "+timeStr;
sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//目标时间 时间戳
long targetTimer= sdf.parse(targetTime).getTime();
//当前时间 时间戳
long currentTimer = new Date().getTime();
//判断是否已过目标时间
if(targetTimer < currentTimer ){
//目标时间加一天
targetTimer += 1000*60*60*24;
}
//返回目标日期
return new Date(targetTimer);
}
}
这份代码有个问题,多次运行后会出现下面的问题:
说明你的系统没有剪切板程序
首先: 在开始->运行中输入clipbrd 回车:
如果系统弹出了剪切板,那你就编辑-删除
如果提示window 没有文件 clipbrd 那就需要去找一个clipbrd.exe程序 放入到
C:WINDOWSsystem32目录下面就可以了.....
最后
以上就是合适白开水为你收集整理的抢羽毛球场地脚本的全部内容,希望文章能够帮你解决抢羽毛球场地脚本所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复