Type a String using java.awt.Robot

前端 未结 7 1830
难免孤独
难免孤独 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:13

    You need to "type" the character, which is a press AND release action...

    robot.keyPress(KeyEvent.VK_1);  
    robot.keyRelease(KeyEvent.VK_1);  
    

    Now you could just copy and paste it three times, but I'd just put it in a loop

提交回复
热议问题