<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    無為

    無為則可為,無為則至深!

      BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
      190 Posts :: 291 Stories :: 258 Comments :: 0 Trackbacks

    Java.awt.Robot 類用于控制鼠標和鍵盤。一旦你得到這種控制,你能夠通過你的Java代碼做與
    鼠標和鍵盤任何類型的操作.這個類通常用于自動化測試。先面的代碼樣例將向您展示Robot
    類如何處理鍵盤事件。如果你運行此代碼,并打開notepad,您將在notepad中看到HI CAOER。趕快試一試吧。
    import java.awt.AWTException;
    import java.awt.Robot;
    import java.awt.event.KeyEvent;

    public class RobotExp {

    public static void main(String[] args) {

    try {

    Robot robot = new Robot();
    //定義5秒的延遲以便你打開notepad 哈哈
    // Robot 開始寫
    robot.delay(5000);
    robot.keyPress(KeyEvent.VK_H);
    robot.keyPress(KeyEvent.VK_I);
    robot.keyPress(KeyEvent.VK_SPACE);
    robot.keyPress(KeyEvent.VK_C);
    robot.keyPress(KeyEvent.VK_A);
    robot.keyPress(KeyEvent.VK_O);
    robot.keyPress(KeyEvent.VK_E);
    robot.keyPress(KeyEvent.VK_R);

    } catch (AWTException e) {
    e.printStackTrace();
    }
    }
    }



    凡是有該標志的文章,都是該blog博主Caoer(草兒)原創,凡是索引、收藏
    、轉載請注明來處和原文作者。非常感謝。

    posted on 2007-08-09 14:59 草兒 閱讀(2879) 評論(12)  編輯  收藏 所屬分類: java

    Feedback

    # re: 如何在Java中使用Robot類 2007-08-09 17:58 bromon
    樓主你好歹也把程序執行一下吧,一看就知道打出來的肯定不是hi budy  回復  更多評論
      

    # re: 如何在Java中使用Robot類 2007-08-09 20:29 pass86
    hi caoer  回復  更多評論
      

    # re: 如何在Java中使用Robot類 2007-08-09 21:22 草兒
    哈哈 我后來改了 HI CAOER   回復  更多評論
      

    # re: 如何在Java中使用Robot類 2007-08-10 11:11 sitinspring
    這個不錯,類似于VBVC的Sendkey,不知有沒有對應的AppActivate函數.  回復  更多評論
      

    # re: 如何在Java中使用Robot類 2007-08-10 11:27 Swing
    其實這個類有時候是很危險的
    它可以輕易的對電腦文件進行拖拽刪除等  回復  更多評論
      

    # re: 如何在Java中使用Robot類 2007-08-10 17:00 HutWang
    很有意思.

    完善下:

    import java.awt.AWTException;
    import java.awt.Robot;
    import java.awt.event.KeyEvent;

    import java.io.IOException;


    public class RobotExp {
    public static void pressKey(Robot robot, int keyvalue) {
    robot.keyPress(keyvalue);
    robot.keyRelease(keyvalue);
    }

    public static void pressKeyWithShift(Robot robot, int keyvalue) {
    robot.keyPress(KeyEvent.VK_SHIFT);
    robot.keyPress(keyvalue);
    robot.keyRelease(keyvalue);
    robot.keyRelease(KeyEvent.VK_SHIFT);
    }

    public static void closeApplication(Robot robot) {
    // pressKey(robot, KeyEvent.VK_ALT);
    // pressKey(robot, KeyEvent.VK_F4);
    robot.keyPress(KeyEvent.VK_ALT);
    robot.keyPress(KeyEvent.VK_F4);
    robot.keyRelease(KeyEvent.VK_ALT);
    robot.keyRelease(KeyEvent.VK_F4);

    //for linux.
    // robot.keyPress(KeyEvent.VK_ALT);
    // robot.keyPress(KeyEvent.VK_W);
    // robot.keyRelease(KeyEvent.VK_ALT);
    // robot.keyRelease(KeyEvent.VK_W);
    robot.keyPress(KeyEvent.VK_N);
    robot.keyRelease(KeyEvent.VK_N);
    }

    public static void main(String[] args) throws IOException {
    try {
    Robot robot = new Robot();
    Runtime.getRuntime().exec("notepad");

    // For linux.
    //Runtime.getRuntime().exec("gedit");
    //定義5秒的延遲以便你打開notepad 哈哈
    // Robot 開始寫
    robot.delay(3000);

    for (int i = 0; i < 100; i++) {
    pressKeyWithShift(robot, KeyEvent.VK_H);
    pressKey(robot, KeyEvent.VK_I);
    pressKey(robot, KeyEvent.VK_SPACE);

    //pressKeyWithShift(robot, KeyEvent.VK_H);
    pressKeyWithShift(robot, KeyEvent.VK_I);
    pressKey(robot, KeyEvent.VK_SPACE);
    pressKey(robot, KeyEvent.VK_A);
    pressKey(robot, KeyEvent.VK_M);
    pressKey(robot, KeyEvent.VK_SPACE);
    pressKey(robot, KeyEvent.VK_T);
    pressKey(robot, KeyEvent.VK_H);
    pressKey(robot, KeyEvent.VK_E);
    pressKey(robot, KeyEvent.VK_SPACE);
    pressKey(robot, KeyEvent.VK_J);
    pressKey(robot, KeyEvent.VK_A);
    pressKey(robot, KeyEvent.VK_V);
    pressKey(robot, KeyEvent.VK_A);
    pressKey(robot, KeyEvent.VK_SPACE);
    pressKey(robot, KeyEvent.VK_R);
    pressKey(robot, KeyEvent.VK_O);
    pressKey(robot, KeyEvent.VK_B);
    pressKey(robot, KeyEvent.VK_O);
    pressKey(robot, KeyEvent.VK_T);

    // VK_ENTER
    pressKey(robot, KeyEvent.VK_ENTER);

    //pressKey(robot, KeyEvent.);
    }

    closeApplication(robot);

    //robot.keyPress(KeyEvent.VK_SPACE);
    } catch (AWTException e) {
    e.printStackTrace();
    }
    }
    }
      回復  更多評論
      

    # re: 如何在Java中使用Robot類 2007-08-10 17:33 sitinspring
    得臨時打開程序啊啊,激活已有程序改怎么做?

      回復  更多評論
      

    # re: 如何在Java中使用Robot類 2007-08-10 22:09 草兒
    你樓上的兄弟已經給了 答案了 哈哈  回復  更多評論
      

    # re: 如何在Java中使用Robot類 2007-08-11 08:10 BeanSoft
    不能打開組合鍵, 郁悶. 誰知道如何模擬像 Ctrl + Space 這樣的按鍵組合?  回復  更多評論
      

    # re: 如何在Java中使用Robot類 2007-08-11 11:06 草兒
    robot.keyPress(KeyEvent.VK_CONTROL);
    robot.keyPress(KeyEvent.VK_SPACE );
    robot.keyRelease(KeyEvent.VK_CONTROL);
    robot.keyRelease(KeyEvent.VK_SPACE);
    這就是組合鍵,但要包括按下和釋放兩個動作  回復  更多評論
      

    # re: 如何在Java中使用Robot類 2007-08-11 11:12 草兒
    "Key pressed" and "key released" events are lower-level and depend on the platform and keyboard layout. They are generated whenever a key is pressed or released, and are the only way to find out about keys that don't generate character input (e.g., action keys, modifier keys, etc.). The key being pressed or released is indicated by the getKeyCode method, which returns a virtual key code.

    Virtual key codes are used to report which keyboard key has been pressed, rather than a character generated by the combination of one or more keystrokes (such as "A", which comes from shift and "a").

      回復  更多評論
      

    # re: 如何在Java中使用Robot類 2007-09-15 21:20 黑蝙蝠
    @pass86
    看來這個和按鍵精靈的思路一致  回復  更多評論
      

    主站蜘蛛池模板: 国产亚洲精久久久久久无码77777 国产亚洲精品成人AA片新蒲金 | 中文字幕人成人乱码亚洲电影| 亚洲人成www在线播放| www视频在线观看免费| 久久亚洲AV成人出白浆无码国产 | 国产成人亚洲综合色影视| 中文字幕成人免费高清在线 | a级成人毛片免费视频高清| 国产亚洲美女精品久久久| 一级午夜a毛片免费视频| 亚洲国产专区一区| 一级做a爰片久久毛片免费看| 亚洲M码 欧洲S码SSS222| 一级成人a做片免费| 在线精品亚洲一区二区小说| 三级网站在线免费观看| 亚洲综合一区二区国产精品| 99久久久国产精品免费牛牛四川| 久久亚洲熟女cc98cm| 亚洲免费二区三区| 在线a亚洲老鸭窝天堂av高清| 思思99re66在线精品免费观看| 亚洲欧美国产欧美色欲| 免费国产真实迷j在线观看| 亚洲视频在线免费| 亚洲av午夜成人片精品网站| 国产a视频精品免费观看| 亚洲国产精品成人综合色在线| 一级毛片直播亚洲| a级片免费在线播放| 亚洲国产美女福利直播秀一区二区| 一个人看www在线高清免费看| 精品国产亚洲一区二区三区在线观看| 在线日韩日本国产亚洲| 又大又硬又爽又粗又快的视频免费| 在线精品亚洲一区二区| 亚洲天堂在线视频| 啦啦啦完整版免费视频在线观看| 亚洲国产精华液2020| 国产亚洲一区二区三区在线| 国产成人精品免费午夜app|