简体   繁体   中英

How to press Enter key using Java?

I want to press Enter Key when a new window pop up for example for downloading a file. I have to press OK button.

So I tried the following code:

Robot r = new Robot();
r.keyPress(KeyEvent.VK_ENTER);
r.keyRelease(KeyEvent.VK_ENTER);

This is just ignoring. Do you have any idea. Thank you

This code simulates pressing the Enter Key:

    Scanner keyboard = new Scanner(System.in);
    keyboard.nextLine();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM