सहायता के लिए मानक कुंजी संयोजन कमांड - है? मैक पर। मैं इस कुंजी संयोजन को मेनू आइटम में कैसे बांध सकता हूं।आदेश कैसे बाध्य करें-? एक सहायता मेनू के लिए एक स्विंग कार्रवाई त्वरक के रूप में?
नोट: चूंकि हमारे उपयोगकर्ताओं के पास अलग-अलग कीबोर्ड लेआउट हैं, मैं ऐसे समाधान की तलाश में हूं जिसके बारे में ज्ञान की आवश्यकता नहीं है "?" पर स्थित है
KeyStroke.getKeyStroke(String)
का उपयोग करके, जो जावाडोक कहता है;
Parses a string and returns a `KeyStroke`. The string must have the following syntax:
<modifiers>* (<typedID> | <pressedReleasedID>)
modifiers := shift | control | ctrl | meta | alt | button1 | button2 | button3
typedID := typed <typedKey>
typedKey := string of length 1 giving Unicode character.
pressedReleasedID := (pressed | released) key
key := KeyEvent key code name, i.e. the name following "VK_".
मैं इस उदाहरण कोड है:
import javax.swing.*;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
public class HelpShortcut extends JFrame {
public HelpShortcut(){
// A few keystrokes to experiment with
//KeyStroke keyStroke = KeyStroke.getKeyStroke("pressed A"); // A simple reference - Works
//KeyStroke keyStroke = KeyStroke.getKeyStroke("typed ?"); // Works
KeyStroke keyStroke = KeyStroke.getKeyStroke("meta typed ?"); // What we want - Does not work
// If we provide an invalid keystroke we get a null back - fail fast
if (keyStroke==null) throw new RuntimeException("Invalid keystroke");
// Create a simple menuItem linked to our action with the keystroke as accelerator
JMenuItem helpMenuItem = new JMenuItem(new HelpAction());
helpMenuItem.setAccelerator(keyStroke);
// Install the menubar with a help menu
JMenuBar mainMenu = new JMenuBar();
JMenu helpMenu = new JMenu("Help");
helpMenu.add(helpMenuItem);
mainMenu.add(helpMenu);
setJMenuBar(mainMenu);
}
// Scaffolding
public static void main(String[] pArgs) {
HelpShortcut helpShortcut= new HelpShortcut();
helpShortcut.setLocationRelativeTo(null);
helpShortcut.setSize(new Dimension(100, 162));
helpShortcut.setVisible(true);
}
private class HelpAction extends AbstractAction {
public HelpAction() {
putValue(Action.NAME,"Help me!");
}
@Override
public void actionPerformed(final ActionEvent pActionEvent) {
JOptionPane.showMessageDialog(HelpShortcut.this,"You should ask StackOverflow!");
}
}
}
बाकी दुनिया सहायता +1 के लिए एफ 1 का उपयोग करें +1 – mKorbel
यह सच है, लेकिन कमांड-? एप्लिकेशन विशिष्ट सहायता के लिए ओएस एक्स मानक है और उपयोगकर्ता क्या उम्मीद करेंगे - ref http://support.apple.com/kb/ht1343 एक और दिलचस्प मुद्दा यह है कि नए मैक पर डिफ़ॉल्ट रूप से एफ-कुंजी मैप किए गए हैं विशेष कार्य (ध्वनि, चमक इत्यादि) और "एफ 1" आदि नहीं है ताकि यह शॉर्टकट उपयोगकर्ता के बिना कीबोर्ड वरीयताओं में सक्षम किए बिना कुछ भी नहीं करेगा। –