zoukankan      html  css  js  c++  java
  • java当脚本用。QQ表白轰炸机

    入坑类似编程,还是要从远古的初中年代,那时为了玩游戏,为了解放双手,接触到某某精灵。

    把java当脚本用,肯定不是我的一个程序,是我万万没想到的一种用法。

    先上图:

    这QQ表白轰炸机,对女神还是要温柔一点的,不然啊,被女神屏蔽了可(偷笑)。

    现附上代码吧

     1 package others;
     2 
     3 import java.awt.AWTException;
     4 import java.awt.Robot;
     5 import java.awt.Toolkit;
     6 import java.awt.datatransfer.StringSelection;
     7 import java.awt.event.KeyEvent;
     8 import java.io.BufferedReader;
     9 import java.io.File;
    10 import java.io.FileInputStream;
    11 import java.io.IOException;
    12 import java.io.InputStreamReader;
    13 import java.util.ArrayList;
    14 
    15 public class QQBomber {
    16 
    17 // bomber 为轰炸机的意思
    18 
    19     public static void main(String[] args) throws AWTException, IOException {
    20         ArrayList<String> str = new ArrayList<String>();
    21         Robot robot = new Robot();
    22         // 静态方法不能用this,啊。
    23 //        File f = new File(this.getClass().getResource("/").getPath()+"SaoSaying.txt");
    24         File f = new File(System.getProperty("user.dir") + "/src/others/SaoSaying.txt");
    25         BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(f)));
    26         String stmp = "";
    27         while (stmp != null) {
    28             stmp = br.readLine();
    29             if (stmp != null)
    30                 str.add(stmp);
    31         }
    32 
    33 //        Iterator<String> it = str.iterator();
    34 //        while (it.hasNext()) {
    35 //            String string = (String) it.next();
    36 //            System.out.println(string);
    37 //        } //迭代看看代码读到了没
    38         
    39         robot.delay(3000);//延迟三秒,把光标定位到聊天窗口
    40         for (int i = 0; i < 5; i++) {
    41 //            随机发
    42 //            StringSelection stsel = new StringSelection(str.get((int) (Math.random() * str.size()-1)));
    43             StringSelection stsel = new StringSelection(str.get(i));
    44             Toolkit.getDefaultToolkit().getSystemClipboard().setContents(stsel, stsel);
    45 
    46             robot.delay(500);
    47             robot.keyPress(KeyEvent.VK_CONTROL);
    48             robot.keyPress(KeyEvent.VK_V);
    49             robot.keyRelease(KeyEvent.VK_CONTROL);
    50             robot.keyRelease(KeyEvent.VK_V);
    51             robot.delay(50);
    52             robot.keyPress(KeyEvent.VK_ENTER);
    53             robot.keyRelease(KeyEvent.VK_ENTER);
    54         }
    55 
    56     }
    57 
    58 }

    从文件中读取到集合中,剪贴板循环集合中的内容(随机也可,记得改循环次数),robot类模拟按键粘贴发送。另外延时太低,会报错嗷,系统粘贴板错误,我无法解决,也觉得没用,慢一点就没问题了,曾经写个try-catch,出错再粘贴一下发送,这样的话可以减少了不能粘贴,程序中断的几率。

    从文件中获取,SAO话,SAO话百度上有。文件路径,用的时候稍微改改就好了。

    今天从文件中获取的时候,发现this关键字不能在静态方法中。因为Static方法是类方法,先于任何的实例(对象)存在。即Static方法在类加载时就已经存在了,但是对象是在创建时才在内存中生成。而this指代的是当前的对象。在方法中定义使用的this关键字,它的值是当前对象的引用.也就是说你只能用它来调用属于当前对象的方法或者使用this处理方法中成员变量和局部变量重名的情况.。而且,更为重要的是this和super都无法出现在static 修饰的方法中,static 修饰的方法是属于类的,该方法的调用者可能是一个类,而不是对象.如果使用的是类来调用而不是对象,则 this就无法指向合适的对象.所以static 修饰的方法中不能使用this——自由自在_Yu

    本来想用这句代码的URL xmlpath = this.getClass().getClassLoader().getResource("1.txt"); 可是不能用。然而,有一网站网友说:Actually. you can call a static method by using an object of the class in which the static method has been declared. Compiler will give no error. We do not do this because its a very bad way of calling/using a static method. :) 谷歌译文:其实, 您可以使用已在其中声明了静态方法的类的对象来调用静态方法。 编译器不会给出任何错误。 我们不这样做,因为这是调用/使用静态方法的一种非常糟糕的方式。 :)。方法很机智,但是好像缺点优雅。

    获得粘贴板的代码,两句,百度复制的。谁都可以。

    robot.delay(500);
    robot.keyPress(KeyEvent.VK_CONTROL);
    robot.keyRelease(KeyEvent.VK_CONTROL);

    robot类,delay方法延迟的,keyPress是按下某个键,keyRelease释放某个键。不然用简单带过吧。

    附上一点点文件内容,百度上有好多嗷,还是稍微改改,才能显出心意吧。

    从前,眼前人是心上人。以后,心上人是枕边人。
    世界并不会对你温柔以待,上帝也不会对你特殊照顾,但我会。
    一生这么长,我需要一个人作伴,说说废话,凑一桌吃饭,把余下的一生都过完,而那个人只能是你。
    纵使生活没那么容易,我还是想把你放在未来里,一生欢喜,不为世俗所及。
    十句搭讪、百句晚安、千句闲聊、万句废话,只为有一天在婚礼堂,听到一句我愿意。
    怎么说呢,你对我笑的时候啊,感觉就好像我是只剩1%电的手机,就在哆哆嗦嗦要关机的那一瞬间,突然被你接上了充电器。

    女神不喜欢简单粗暴,可要温柔哦。

    趁早解放双手,不要码代码了,当一条鲜鱼吧,快乐的蹦跶。

  • 相关阅读:
    composer 中国全量镜像 laravel-china.org
    Increase PHP script execution time with Nginx
    How to make a USB stick use ISO image file in debian
    Getting svn to ignore files and directories
    Carbon document
    Use Laravel/homestead 环境维护基于 brophp 开发的老项目
    Vagrant WinNFSd
    How to use jQuery countdown plugin
    消息系统的设计与实现
    VMvare 复制的数据库,需要改变的配置
  • 原文地址:https://www.cnblogs.com/friend-c/p/12805602.html
Copyright © 2011-2022 走看看