Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

to identify keypressed event in java

 
Gayani Kanchana
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my program i want some task to run when user pressed any key.i am running my program in console mode.how to identify when user press any key.please help.

thanks
 
Joe Ess
Bartender
Posts: 9311
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can't be done in the J2SE. The stream from the console is buffered, so we only get data after a line feed (i.e. after the user presses "enter").
I've done it using JNI, but really, if you want a fully-featured GUI, use AWT or Swing.
 
sudhakar ananth
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you tell how to do in swing
it really needed to me...
bye...
 
Joe Ess
Bartender
Posts: 9311
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Java Tutorial: How to write a Key Listener
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic