package com.zl.wx;
import java.awt.*;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable;
import java.awt.event.KeyEvent;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.TimerTask;
public class T6 extends TimerTask{
private String friendNickName;
private String message;
public T6(String friendNickName,String message){
this.friendNickName = friendNickName;
this.message = message;
}
public static void main(String[] args) throws InterruptedException{
// 好友昵称
String friendNickName = "文件传输助手";
searchMyFriendAndSend(friendNickName , null);
}
private static void searchMyFriendAndSend(String friendNickName , String message) throws InterruptedException{
// 创建Robot对象
Robot robot = null;
try {
robot = new Robot();
} catch (AWTException e) {
e.printStackTrace();
}
//打开微信 Ctrl+Alt+W
assert robot != null;
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_ALT);
robot.keyPress(KeyEvent.VK_W);
//释放Ctrl按键,像Ctrl,退格键,删除键这样的功能性按键,在按下后一定要释放
robot.keyRelease(KeyEvent.VK_CONTROL);
robot.keyRelease(KeyEvent.VK_ALT);
// 该延迟不能少,否则无法搜索
robot.delay(1000);
// Ctrl + F 搜索指定好友
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_F);
robot.keyRelease(KeyEvent.VK_CONTROL);
// 将好友昵称发送到剪切板
Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard();
Transferable tText = new StringSelection(friendNickName);
clip.setContents(tText, null);
// 以下两行按下了ctrl+v,完成粘贴功能
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_CONTROL);
robot.delay(1000);
robot.keyPress(KeyEvent.VK_ENTER);
// 发送消息
sendMsg(message);
}
static String[] emo = {"[嘴唇]","[玫瑰]","[爱心]","[色]","[憨笑]","[亲亲]","[可怜]","[笑脸]","[机智]","[加油]","[拥抱]","[坏笑]","[鼓掌]","[调皮]","[害羞]","[呲牙]","[微笑]"};
static Set set = new HashSet();
static int emoNum = 5;//显示表情个数
static void getIndex(){
int emoLength = emo.length;
Random r = new Random();
int i = r.nextInt(emoLength);
set.add(i);
if(set.size() < emoNum) {
getIndex();
}
}
static String getRandEmo(){
getIndex();
String str = "";
for (Object o: set) {
str += emo[(Integer)o];
}
return str;
}
private static void sendMsg(String message) throws InterruptedException{
String emos = getRandEmo();
if(null == message || "".equals(message)) {
message = "该补充水分了";
}
String[] mottoes = {
// "浮世三千,吾爱有三\n日,月,与卿\n日为朝,月为暮,卿为朝朝暮暮\n\n老婆婆:该补充水分了!" + emos
message + "\n" + emos
};
for (String motto: mottoes) {
sendOneMsg(motto);
}
Thread.sleep(2000);
// sendOneMsg("[得意]就问你,腻不腻害!");
}
private static void sendOneMsg(String msg){
Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard();
Transferable tText;
Robot robot = null;
try {
robot = new Robot();
} catch (AWTException e) {
e.printStackTrace();
}
//延迟十秒,主要是为了预留出打开窗口的时间,括号内的单位为毫秒
assert robot != null;
robot.delay(500);
tText = new StringSelection(msg);
clip.setContents(tText, null);
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_CONTROL);
robot.delay(500);
robot.keyPress(KeyEvent.VK_ENTER);
robot.delay(500);
}
@Override
public void run(){
if(null == friendNickName || "".equals(friendNickName)) {
throw new RuntimeException("未设置发送人昵称");
}
try {
searchMyFriendAndSend(friendNickName , message);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
self-stu.7z (15个子文件)
self-stu
self-stu.iml 81B
pom.xml 572B
src
test
java
main
resources
META-INF
MANIFEST.MF 56B
java
META-INF
MANIFEST.MF 56B
com
zl
wx
SendJob.java 551B
T6.java 5KB
.idea
jarRepositories.xml 883B
artifacts
self_stu_jar.xml 456B
workspace.xml 5KB
misc.xml 526B
compiler.xml 541B
.gitignore 210B
target
classes
META-INF
MANIFEST.MF 56B
com
zl
wx
SendJob.class 969B
T6.class 4KB
generated-sources
annotations
共 15 条
- 1
资源评论
rdsgf
- 粉丝: 57
- 资源: 26
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功