Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
bahtiyor ahmedov
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20665
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
bahtiyor ahmedov
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot to Rob !!!
I have found in C/C++ _kbhit() function for this purpose and getc() also.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic