Type a String using java.awt.Robot

前端 未结 7 1863
难免孤独
难免孤独 2020-12-10 00:46

I already know how to use java.awt.Robot to type a single character using keyPress, as seen below. How can I simply enter a whole

7条回答
  •  佛祖请我去吃肉
    2020-12-10 01:18

    You can enter value in a string and then you can use that string as explained by Eng.Fouad. But there is no fun in using it, you can give a try to this

    Robot robot = new Robot();
    robot.keyPress(KeyEvent.VK_H);
    robot.keyRelease(KeyEvent.VK_H);
    robot.keyPress(KeyEvent.VK_E);
    robot.keyRelease(KeyEvent.VK_E);
    robot.keyPress(KeyEvent.VK_L);
    robot.keyRelease(KeyEvent.VK_L);
    robot.keyPress(KeyEvent.VK_L);
    robot.keyRelease(KeyEvent.VK_L);
    robot.keyPress(KeyEvent.VK_O);
    robot.keyRelease(KeyEvent.VK_O);
    

    and you can also use Thread.sleep so that it can enter data bit slowly.

提交回复
热议问题