Here you can find the source of getKeyStrokeRepresentation(KeyStroke ks)
modifier+modifier+...+key
For example, KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_MASK|InputEvent.ALT_MASK)
will return Ctrl+Alt+C
.
Parameter | Description |
---|---|
ks | the KeyStroke for which to return a String representation |
[modifier]+[modifier]+...+key
format
public static String getKeyStrokeRepresentation(KeyStroke ks)
//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 )", ""); } }