Java Swing Key Action getKeyStrokeRepresentation(KeyStroke ks)

Here you can find the source of getKeyStrokeRepresentation(KeyStroke ks)

Description

Returns a String representation for the given KeyStroke for display, in the following format:
modifier+modifier+...+key

For example, KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_MASK|InputEvent.ALT_MASK) will return Ctrl+Alt+C.

License

Open Source License

Parameter

Parameter Description
ks the KeyStroke for which to return a String representation

Return

a String representation of the given KeyStroke for display, in the [modifier]+[modifier]+...+key format

Declaration

public static String getKeyStrokeRepresentation(KeyStroke ks) 

Method Source Code

//package com.java2s;
/*//  w ww . j  av a 2  s.  c o m
 * This file is part of muCommander, http://www.mucommander.com
 * Copyright (C) 2002-2016 Maxence Bernard
 *
 * muCommander is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * muCommander is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import javax.swing.KeyStroke;

public class Main {
    /**
     * Returns a String representation for the given KeyStroke for display, in the following format:<br>
     * <code>modifier+modifier+...+key</code>
     *
     * <p>For example, <code>KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_MASK|InputEvent.ALT_MASK)</code>
     * will return <code>Ctrl+Alt+C</code>.</p>
     *
     * @param ks the KeyStroke for which to return a String representation
     * @return a String representation of the given KeyStroke for display, in the <code>[modifier]+[modifier]+...+key</code> format
     */
    public static String getKeyStrokeRepresentation(KeyStroke ks) {
        return ks.toString().replaceFirst(
                "(released )|(pressed )|(typed )", "");
    }
}

Related

  1. getActionInstanceName(Action delegate)
  2. getEscapeKeystroke()
  3. getKeyStroke(int i0, int i1)
  4. getKeystroke(int keyevent)
  5. getKeyStrokeCopy()
  6. getKeyStrokeText(KeyStroke ks)
  7. getPrettyStringFor(KeyStroke keyStroke)
  8. getSystemHelpKey()
  9. getTypePanel(final ActionListener typeListener)