hello friends,
how do I simulate an "enter" key press in java?
this is to avoid the continuous key pressing during runtime whereas there are so many popups which require an "enter" key press to continue execution
hello friends,
how do I simulate an "enter" key press in java?
this is to avoid the continuous key pressing during runtime whereas there are so many popups which require an "enter" key press to continue execution
You can post an ActionEvent for the component. For example:
Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(
new ActionEvent(src, // the component
ActionEvent.ACTION_PERFORMED,
"Enter"));
What is the GUI interaction with a user? How do you detect that an Event should be sent to a component?
You can post an ActionEvent for the component. For example:
Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent( new ActionEvent(src, // the component ActionEvent.ACTION_PERFORMED, "Enter"));
What is the GUI interaction with a user? How do you detect that an Event should be sent to a component?
hello,
there is a .cmd file I need to execute via the java program, once it's executed it requires a confirmation from the user as to whether continue or not..(asking a Y or N in the command prompt)....I want to skip this part by always letting it to execute (which means always users answer will be Y)...that's why I thought of giving it an enter key press event once the question pops up...
this is the code that I use to invoke the external program,
try {
String line;
File file=new File("E:/HarvestCruise/build_current/source/_ant_compile.cmd");//
File output=new File("Out.txt");
Runtime.getRuntime().exec ("rundll32 SHELL32.DLL,ShellExec_RunDLL" +file.getAbsolutePath());
//at this point the external program starts to run and asks the user whether to continue or not, this is the point where i need to give a key press.
}
catch (Exception err) {
err.printStackTrace();
}
Your java program can NOT send events to another program.
You can use the Robot class to move the cursor and do key presses.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.