Java examples for Swing:Key Event
Returns a key stroke with the modifiers #getMenuShortcutMask() and ALT down.
//package com.java2s; import java.awt.Toolkit; import java.awt.event.InputEvent; import javax.swing.KeyStroke; public class Main { /**//from w ww . j ava 2 s . c o m * Returns a key stroke with the modifiers {@code #getMenuShortcutMask()} * and ALT down. * * @param keyCode key code * @return key stroke */ public static KeyStroke getKeyStrokeMenuShortcutWithAltDown(int keyCode) { return KeyStroke.getKeyStroke(keyCode, getMenuShortcutMask() | InputEvent.ALT_DOWN_MASK); } /** * Returns a key stroke without modifiers. * * @param keyCode key code * @return key stroke */ public static KeyStroke getKeyStroke(int keyCode) { return KeyStroke.getKeyStroke(keyCode, 0); } /** * The same as {@code Toolkit#getMenuShortcutKeyMask()}. * * @return mask */ public static int getMenuShortcutMask() { return Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(); } }