Browse Source

增加oneonte自动标题功能。

liuyuqi-dellpc 6 years ago
parent
commit
2796fdf2b9
1 changed files with 102 additions and 0 deletions
  1. 102 0
      src/me/yoqi/mRobot/OneNoteTitle.java

+ 102 - 0
src/me/yoqi/mRobot/OneNoteTitle.java

@@ -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;
+
+/**实现自动分行程序,减少重复劳动,后续键盘全局监听事件,实现按enter键后自动停止程序。
+ * @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) {
+						// TODO Auto-generated catch block
+						e.printStackTrace();
+					}
+				}
+			}
+		}.start();
+
+		// 获取main线程
+		Thread main = Thread.currentThread();
+		System.out.println(main.getName());
+		main.interrupt();
+		System.out.println("main线程已经退出了,但是不影响其他线程运行!");
+		// System.exit(0);
+
+	}
+	public void formatTitle() throws AWTException {
+		robot = new Robot();
+		// 延时5s,执行程序。5s内把光标对准到要输入的文本框或者
+		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); // end
+			robot.keyRelease(KeyEvent.VK_END);
+			robot.delay(200);
+
+			robot.keyPress(KeyEvent.VK_ENTER); // enter
+			robot.keyRelease(KeyEvent.VK_ENTER);
+			robot.delay(200);
+
+			robot.keyPress(KeyEvent.VK_ENTER); // enter
+			robot.keyRelease(KeyEvent.VK_ENTER);
+			robot.delay(200);
+
+		}
+	}
+
+	public void stop(KeyEvent e) {
+		// 如果按ESC键
+		if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
+			this.flag = !this.flag;
+		}
+	}
+
+	@Override
+	public void keyTyped(KeyEvent e) {
+		// TODO 自动生成的方法存根
+		
+	}
+
+	@Override
+	public void keyPressed(KeyEvent e) {
+		// TODO 自动生成的方法存根
+		
+	}
+
+	@Override
+	public void keyReleased(KeyEvent e) {
+		// TODO 自动生成的方法存根
+		
+	}
+}