aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes How to detect user key presses such as conrtrol-P, control-S, and control-M Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to detect user key presses such as conrtrol-P, control-S, and control-M" Watch "How to detect user key presses such as conrtrol-P, control-S, and control-M" New topic
Author

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

Nate Lockwood
Ranch Hand

Joined: Feb 22, 2010
Posts: 83
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

Joined: Jun 09, 2003
Posts: 4632
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
 
subject: How to detect user key presses such as conrtrol-P, control-S, and control-M