This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes SWT - Mapping key actions (ie Ctrl+S = Save) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "SWT - Mapping key actions (ie Ctrl+S = Save)" Watch "SWT - Mapping key actions (ie Ctrl+S = Save)" New topic
Author

SWT - Mapping key actions (ie Ctrl+S = Save)

Ivan Jouikov
Ranch Hand

Joined: Jul 22, 2003
Posts: 269
How the hell do you do that? I spent the last two hours searching google with absolutely no result!

shell.addKeyListener( new KeyAdapter ... doesn't work. It works if I add it to a text box, but how would I make a global key listener event?

This is driving me crazy, please help
Nick Kocher
Greenhorn

Joined: Nov 24, 2004
Posts: 14
Privet Ivan!
If you need Ctrl + s for your menuItem in the menu for example, you could use the following code:
menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK));
Ivan Jouikov
Ranch Hand

Joined: Jul 22, 2003
Posts: 269
Omg that did the trick!

Thanks!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: SWT - Mapping key actions (ie Ctrl+S = Save)
 
Similar Threads
how to detect game action in game loop?
porting prob in motorola V600
Help! Problem using 1:1 CMP Relationship example using JBoss 3.0.0
Key accelerator question
one-to-many relation