File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to detect user key presses such as conrtrol-P, control-S, and control-M

 
Nate Lockwood
Ranch Hand
Posts: 83
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a GUI (JFrame) with 3 panels. I'd like the user to be able to type control-key pairs such as: control-P to start a print job and control-S to save but don't see how to do this with KeyListener.

If the "if" statement is removed or I change the if statement to if (!arg0.isControlDown()) { the switch works whether the control key is pressed or not. Otherwise nothing happens. I'm on OS-X right now and need this to work with LINUX as well (and probably MS XP at some point).
 
Michael Dunn
Ranch Hand
Posts: 4632
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
KeyBindings is what you want.

http://docs.oracle.com/javase/tutorial/uiswing/misc/keybinding.html
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic