In C, we could use getch() form <conio.h> to get a character from the input steam without pressing the return/enter key. How could I tranlate this function for use in Java?:confused:
In C, we could use getch() form <conio.h> to get a character from the input steam without pressing the return/enter key. How could I tranlate this function for use in Java?:confused:
Code:
import java.awt.event.*;
class Keyboard extends KeyAdapter{
public void keyPressed(KeyEvent ke){
Character text = new Character(ke.getKeyChar());
jta.append(text.toString());
}
}
Hi <Dilenger4>, is the class that you suggested used for instantiating a Listener object that must be in associating with a GUI object?
Hi :) Yes it is a Listener object that is
associated with a JTextArea.
Alright, so this means that I can't do it purely in the console DOS mode without the help of a GUI. Anyway, thanx a lot for your help!
:eek:
You could do somthing like this.
Just don't hit the enter key until
you want to exit back to the prompt
or you will just get a lot of numbers
that could interfere with your program. :p
Code:import java.io.*;
public class Grabber{
public static void main(String[] args){
for(;;){
try{
int data = System.in.read();
if(data == 27){ // esc key
break;
}
System.out.print(data);
}catch(IOException e ){}
}
}
}