Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

how to output a variable in java using awt.robot?

ok so i know you can output a using "keyPress(KeyEvent.VK_A)" but is there a way to output a variable?? like:

String str= "hello";

What would the code be to output this?

Update:

im sorry, i should have specified: i want to get an input from the user (probably an output screen/system.out/in) then write that into say, an firefox window.... i could click the window, and using robot, type a or whatever, but the best way i can think of to output a String is to have a big if statement with a for loop, is there a better way?

2 Answers

Relevance
  • 1 decade ago
    Favorite Answer

    You mean you want to use the Robot class to push each of the keys in order? If so then:

    Robot r = new Robot();

    for(char c : str.toCharArray()){

    r.keyPress(c);

    r.keyRelease(c);

    }

    And in response to the previous answer, yes the Robot class keyPress does serve a purpose more than just to screw a computer... I've used it before for useful purposes.

  • 1 decade ago

    What do you mean by outputting a variable using Robot?

    Robot is for emulating mouse and keyboard events (I personally use it to screw a computer by clicking several hundred times a second) and taking screenshots, but other than that serves no purpose. To output the value of the variable, use System.out.println(), like the common mortal, a drawString() or setLabel() in a GUI or write() to a file for advanced people

Still have questions? Get your answers by asking now.