Returns a key stroke with the modifiers #getMenuShortcutMask() and SHIFT down. - Java Swing

Java examples for Swing:Key Event

Description

Returns a key stroke with the modifiers #getMenuShortcutMask() and SHIFT down.

Demo Code


//package com.java2s;
import java.awt.Toolkit;
import java.awt.event.InputEvent;

import javax.swing.KeyStroke;

public class Main {
    /**// ww w .  ja  v  a 2  s  .  c  om
     * Returns a key stroke with the modifiers {@code #getMenuShortcutMask()}
     * and SHIFT down.
     *
     * @param  keyCode key code
     * @return         key stroke
     */
    public static KeyStroke getKeyStrokeMenuShortcutWithShiftDown(
            int keyCode) {
        return KeyStroke.getKeyStroke(keyCode, getMenuShortcutMask()
                | InputEvent.SHIFT_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();
    }
}

Related Tutorials