赞
踩
-
-
- import lombok.SneakyThrows;
- 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.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.Calendar;
- import java.util.Date;
- import java.util.Timer;
- import java.util.TimerTask;
-
- /**
- * 定时给指定微信好友发送
- */
- public class WcharTest {
- public static void main(String[] args) throws ParseException {
- // 好友昵称
- String friendNickName = "文件传输助手";// "文件传输助手";
- String msg="测试发送消息00";//发送内容
- Timer timer = new Timer();
- SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- Date date = format.parse("2023-07-03 14:43:00");
- System.out.println("进入定时器");
- timer.schedule(new TimerTask() {
- @SneakyThrows
- @Override
- public void run() {
- sendMsgforSp(friendNickName, msg);
- }
- },date);
- System.out.println("结束");
- }
-
- /**
- * 发送消息给好友
- * @param friendNickName 指定好友
- * @param msg 消息内容
- * @throws AWTException
- */
- private static void sendMsgforSp(String friendNickName, String msg) throws AWTException {
- //创建robot对象
- Robot robot = new Robot();
- //第一步:打开微信 control+alt+w
- 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);
- robot.delay(1000);
-
- //第三步发送消息
- //发送消息
- // 将字符串复制到剪切板
- Transferable tText1 = new StringSelection(msg);
- clip.setContents(tText1, null);
- // 以下两行按下了ctrl+v,完成粘贴功能
- robot.keyPress(KeyEvent.VK_CONTROL);
- robot.keyPress(KeyEvent.VK_V);
- robot.keyRelease(KeyEvent.VK_CONTROL);
- // 回车发送
- robot.keyPress(KeyEvent.VK_ENTER);
- robot.delay(1000);
- }
-
-
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。