|
@@ -0,0 +1,102 @@
|
|
|
+
|
|
|
+ *
|
|
|
+ */
|
|
|
+package me.yoqi.mRobot;
|
|
|
+
|
|
|
+import java.awt.AWTException;
|
|
|
+import java.awt.Robot;
|
|
|
+import java.awt.event.KeyEvent;
|
|
|
+import java.awt.event.KeyListener;
|
|
|
+
|
|
|
+
|
|
|
+ * @author liuyuqi
|
|
|
+ *
|
|
|
+ */
|
|
|
+public class OneNoteTitle implements KeyListener{
|
|
|
+ private static Robot robot;
|
|
|
+ private boolean flag;
|
|
|
+ private String threadName;
|
|
|
+
|
|
|
+ public static void main(String[] args) throws AWTException {
|
|
|
+
|
|
|
+ (new OneNoteTitle("o1")).formatTitle();
|
|
|
+ }
|
|
|
+
|
|
|
+ public OneNoteTitle(String name) {
|
|
|
+ threadName = name;
|
|
|
+ System.out.println("Creating " + threadName);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void newThread() {
|
|
|
+ System.out.println("开始进入程序...");
|
|
|
+ new Thread("o2") {
|
|
|
+ public void run() {
|
|
|
+ while (true) {
|
|
|
+ System.out.println("我是另外的线程...");
|
|
|
+ try {
|
|
|
+ Thread.sleep(1000);
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }.start();
|
|
|
+
|
|
|
+
|
|
|
+ Thread main = Thread.currentThread();
|
|
|
+ System.out.println(main.getName());
|
|
|
+ main.interrupt();
|
|
|
+ System.out.println("main线程已经退出了,但是不影响其他线程运行!");
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ public void formatTitle() throws AWTException {
|
|
|
+ robot = new Robot();
|
|
|
+
|
|
|
+ robot.delay(5000);
|
|
|
+ for (int i = 0; i < 50; i++) {
|
|
|
+ robot.keyPress(KeyEvent.VK_DOWN);
|
|
|
+ robot.keyRelease(KeyEvent.VK_DOWN);
|
|
|
+ robot.delay(200);
|
|
|
+
|
|
|
+ robot.keyPress(KeyEvent.VK_END);
|
|
|
+ robot.keyRelease(KeyEvent.VK_END);
|
|
|
+ robot.delay(200);
|
|
|
+
|
|
|
+ robot.keyPress(KeyEvent.VK_ENTER);
|
|
|
+ robot.keyRelease(KeyEvent.VK_ENTER);
|
|
|
+ robot.delay(200);
|
|
|
+
|
|
|
+ robot.keyPress(KeyEvent.VK_ENTER);
|
|
|
+ robot.keyRelease(KeyEvent.VK_ENTER);
|
|
|
+ robot.delay(200);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void stop(KeyEvent e) {
|
|
|
+
|
|
|
+ if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
|
|
|
+ this.flag = !this.flag;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void keyTyped(KeyEvent e) {
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void keyPressed(KeyEvent e) {
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void keyReleased(KeyEvent e) {
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+}
|