File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes I/O and Streams and the fly likes Console Chat application problem or how to handle KeyPress event in console Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Console Chat application problem or how to handle KeyPress event in console" Watch "Console Chat application problem or how to handle KeyPress event in console" New topic
Author

Console Chat application problem or how to handle KeyPress event in console

bahtiyor ahmedov
Greenhorn

Joined: Jan 12, 2007
Posts: 10
Dear Java professionals! advice me please

>>>problem with console chat application.

is there any way of handling user keypress in console (is user typing any message or not!!!) ?
i have tried :
BufferedReader br = new BufferedReader(
new InputStreamReader(System.in));
.....
a) int i = br.read();
............
b) if (br.ready())
............
c) DataInputStream dis = .....
if (dis.available() == 0)

this methods require of ENTER (CR) key press.
but by these methods i cannot get, Is user typing or not !

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19760
    
  20

The Java API has nothing for this. You can use JNI for this, using the getc function call, since that does not wait for an enter; it returns immediately after one single character has been typed in.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
bahtiyor ahmedov
Greenhorn

Joined: Jan 12, 2007
Posts: 10
Thanks a lot to Rob !!!
I have found in C/C++ _kbhit() function for this purpose and getc() also.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Console Chat application problem or how to handle KeyPress event in console