Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

problem to listen key board event  RSS feed

 
vaibhav agarwal
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have to listen CTRL key event on panel... can any one send sample code......

Thanks
Vaibhav
 
Stuart Gray
Ranch Hand
Posts: 410
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to add a KeyListener to your JPanel. Then you want to deal with either keyPressed or keyReleased events, not keyTyped events (since the Control key is an action key that produces no character). Here is a short example:
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!