This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

to identify keypressed event in java  RSS feed

 
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: 9428
12
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: 9428
12
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
Boost this thread!