Here you can find the source of keyStrokeToString(KeyStroke key)
public static String keyStrokeToString(KeyStroke key)
//package com.java2s; import java.awt.Event; import javax.swing.KeyStroke; import java.awt.event.KeyEvent; public class Main { /** Return a good string representation of the given keystroke, since * the toString method returns more garbage than we want to see in a * user interface./*from w ww . jav a 2s.c o m*/ */ public static String keyStrokeToString(KeyStroke key) { int modifiers = key.getModifiers(); StringBuffer buffer = new StringBuffer(); if ((modifiers & Event.SHIFT_MASK) == Event.SHIFT_MASK) { buffer.append("(Shift-"); buffer.append(KeyEvent.getKeyText(key.getKeyCode())); buffer.append(")"); } if ((modifiers & Event.CTRL_MASK) == Event.CTRL_MASK) { buffer.append("(Ctrl-"); buffer.append(KeyEvent.getKeyText(key.getKeyCode())); buffer.append(")"); } if ((modifiers & Event.META_MASK) == Event.META_MASK) { buffer.append("(Meta-"); buffer.append(KeyEvent.getKeyText(key.getKeyCode())); buffer.append(")"); } if ((modifiers & Event.ALT_MASK) == Event.ALT_MASK) { buffer.append("(Alt-"); buffer.append(KeyEvent.getKeyText(key.getKeyCode())); buffer.append(")"); } if (modifiers == 0) { buffer.append("("); buffer.append(KeyEvent.getKeyText(key.getKeyCode())); buffer.append(")"); } return buffer.toString(); } }