Java uses Robot bomber to complete the QQ

effect

Online noisy quarrel but how other people do? Girlfriend let you count from 1 to 10,000 how to do? I want to spoof a friend how to do? QQ bomber you deserve! (Note: In order to better learning programming, practiced hand to knock the project, only to make learning to use)
to customize the content is sent, the custom to send several "love" him, Kill him fried!

Source

In fact, the idea is very simple, using the Java Robot class to do inside the simulated keyboard operation, the basic idea is that we make a copy for some words, and then write cycles in the loop simulation press ctrl + v key to complete the paste function, paste End simulated press Enter (transmission).
Robot class can emulate keyboard and mouse operation, usually used to do some automated testing and the like, or do some simple but requires frequent operations functions. Like grab a red envelope, brush ticket can be used to do the Robot, ideas are similar. If you are busy enough, you can even write a class to break the cycle WiFi password

import java.awt.AWTException;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable;
import java.awt.event.KeyEvent;

public class QQBoom {
    public static void main(String[] args) throws AWTException {

        String sentence = "爱我你怕了吗";//定义要发送的话
        
        //以下三行为将上述字符串放到剪切板内,相当于做了一次复制操作
        Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard();
        Transferable tText = new StringSelection(sentence);
        clip.setContents(tText, null);
        

        Robot robot = new Robot();//创建Robot对象
        robot.delay(3000);//延迟三秒,主要是为了预留出打开窗口的时间,括号内的单位为毫秒
        for (int i = 1; i <= 10; i++) {//循环十次,当然,如果爱得深,你死循环也没问题
            
            //以下两行按下了ctrl+v,完成粘贴功能
            robot.keyPress( KeyEvent.VK_CONTROL);
            robot.keyPress(KeyEvent.VK_V);
            
            robot.keyRelease(KeyEvent.VK_CONTROL);//释放ctrl按键,像ctrl,退格键,删除键这样的功能性按键,在按下后一定要释放,不然会出问题。crtl如果按住没有释放,在按其他字母按键是,敲出来的回事ctrl的快捷键。
            robot.keyPress( KeyEvent.VK_ENTER);//回车
        }
    }
}

explain

In fact, nothing to talk about, something so simple, if not for Minato words, I did not write it!

I was wrong, but it is still a great demand, such as, for example ...... such as the release button.
Interested can try red box delete this line is not found out the news release, if you test in Notepad, you will not find the keyboard typing, if you press f will direct the search box pops up, because ctrl functional keys must be released, otherwise it will always work.

From the above example, if there are any evil thoughts, if the code has written a cycle of death, then hold down the button and hold it back_space? You try chanting, the keyboard can play word I lost count. Of course, you can also hold down the delete hold.
Similarly, we can also go to operate a mouse, has been met with some sleepless nights playing games roommate, then reasonable "waste" his keyboard and mouse. Spoof on small things, I wrote an article about lead

Guess you like

Origin www.cnblogs.com/duibd/p/11074758.html