java控制电脑给对方微信发消息

1.打开微信窗口

public void openWeChat() {
        //判断当前系统释放支持Desktop提供的接口
        if (Desktop.isDesktopSupported()) {
            try {
//打开微信窗口
                desktop.open(new File("C:\\Program Files (x86)\\Tencent\\WeChat\\WeChat.exe"));
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

2.选择好友

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);
 
}

3.发消息

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);
}

你可能感兴趣的:(java,微信,开发语言)