I used Robot class to mimic Enter key, and it worked as Norm suggested in https://www.javaprogrammingforums.co...t-console.html.
However, it is dangerous to use Robot class since when focus changes while Robot class continues to work in background(i.e. the program did not end). Because, Robot continues to press keys until the end of the program it continues to press that key to each new focused windows.
So I want to mimic "Enter Key" in console by using ANSI Escape codes such as by writing "\13"(CR) and "\10"(LF) to console. But not success.
I want to use below code to which character sent does "put entered input to stream" functionality as Enter key does. I used below code :
import java.io.*; public class Main { public Main() throws IOException { doInput(); } private void doInput() throws IOException{ InputStream in=System.in; int read=0; read=in.read(); w(" readed integer is :"+Character.getNumericValue((char)read)+".."); } public static void main(String[] args) throws IOException{ new Main(); } private static void w(String s) { System.out.println(s); } }
When I just "Enter key" to send as input, output becomes :
I tried to send -1 integer to console using System.out( after reading these two PrintStream - System.out Java doc and PrintStream's print(int i) method in Java doc) it just wirtes -1 to screen, it does not mimic "Enter key pressed". Also I send "\13" and "\10"(i.e CR and LF ANSI escape codes ) but it does not mimic anything other than LF (just goes to next line). Output is simply "a-1".readed integer is :-1..
1. Which ANSI escape code mimics "Enter Key pressed" in Unix/Windows terminal console?
2. Why "\10" or "\13" (i.e. LF and CR ASCII chars?) does not mimic end of input?
3. How can I mimic "Enter key", which character I have to send to console to put input before it to InputStream(i.e. System.in) ?
Any help is appreciated.