List of usage examples for java.awt.event KeyEvent getKeyText
public static String getKeyText(int keyCode)
From source file:Main.java
private void displayInfo(KeyEvent e, String keyStatus) { // You should only rely on the key char if the event // is a key typed event. int id = e.getID(); String keyString;/*from www . j av a 2 s . co m*/ if (id == KeyEvent.KEY_TYPED) { char c = e.getKeyChar(); keyString = "key character = '" + c + "'"; } else { int keyCode = e.getKeyCode(); keyString = "key code = " + keyCode + " (" + KeyEvent.getKeyText(keyCode) + ")"; } int modifiersEx = e.getModifiersEx(); String modString = "extended modifiers = " + modifiersEx; String tmpString = KeyEvent.getModifiersExText(modifiersEx); System.out.println(e.getWhen()); if (tmpString.length() > 0) { modString += " (" + tmpString + ")"; } else { modString += " (no extended modifiers)"; } String actionString = "action key? "; if (e.isActionKey()) { actionString += "YES"; } else { actionString += "NO"; } String locationString = "key location: "; int location = e.getKeyLocation(); if (location == KeyEvent.KEY_LOCATION_STANDARD) { locationString += "standard"; } else if (location == KeyEvent.KEY_LOCATION_LEFT) { locationString += "left"; } else if (location == KeyEvent.KEY_LOCATION_RIGHT) { locationString += "right"; } else if (location == KeyEvent.KEY_LOCATION_NUMPAD) { locationString += "numpad"; } else { // (location == KeyEvent.KEY_LOCATION_UNKNOWN) locationString += "unknown"; } displayArea.append(keyStatus + newline + " " + keyString + newline + " " + modString + newline + " " + actionString + newline + " " + locationString + newline); displayArea.setCaretPosition(displayArea.getDocument().getLength()); }
From source file:Main.java
private void displayInfo(KeyEvent e, String keyStatus) { // You should only rely on the key char if the event // is a key typed event. int id = e.getID(); String keyString;/*ww w. j a va 2 s. c o m*/ if (id == KeyEvent.KEY_TYPED) { char c = e.getKeyChar(); keyString = "key character = '" + c + "'"; } else { int keyCode = e.getKeyCode(); keyString = "key code = " + keyCode + " (" + KeyEvent.getKeyText(keyCode) + ")"; } int modifiersEx = e.getModifiersEx(); String modString = "extended modifiers = " + modifiersEx; String tmpString = KeyEvent.getModifiersExText(modifiersEx); System.out.println(e.isAltDown()); if (tmpString.length() > 0) { modString += " (" + tmpString + ")"; } else { modString += " (no extended modifiers)"; } String actionString = "action key? "; if (e.isActionKey()) { actionString += "YES"; } else { actionString += "NO"; } String locationString = "key location: "; int location = e.getKeyLocation(); if (location == KeyEvent.KEY_LOCATION_STANDARD) { locationString += "standard"; } else if (location == KeyEvent.KEY_LOCATION_LEFT) { locationString += "left"; } else if (location == KeyEvent.KEY_LOCATION_RIGHT) { locationString += "right"; } else if (location == KeyEvent.KEY_LOCATION_NUMPAD) { locationString += "numpad"; } else { // (location == KeyEvent.KEY_LOCATION_UNKNOWN) locationString += "unknown"; } displayArea.append(keyStatus + newline + " " + keyString + newline + " " + modString + newline + " " + actionString + newline + " " + locationString + newline); displayArea.setCaretPosition(displayArea.getDocument().getLength()); }
From source file:Main.java
private void displayInfo(KeyEvent e, String keyStatus) { // You should only rely on the key char if the event // is a key typed event. int id = e.getID(); String keyString;// ww w . ja v a 2s .com if (id == KeyEvent.KEY_TYPED) { char c = e.getKeyChar(); keyString = "key character = '" + c + "'"; } else { int keyCode = e.getKeyCode(); keyString = "key code = " + keyCode + " (" + KeyEvent.getKeyText(keyCode) + ")"; } int modifiersEx = e.getModifiersEx(); String modString = "extended modifiers = " + modifiersEx; String tmpString = KeyEvent.getModifiersExText(modifiersEx); System.out.println(e.isShiftDown()); if (tmpString.length() > 0) { modString += " (" + tmpString + ")"; } else { modString += " (no extended modifiers)"; } String actionString = "action key? "; if (e.isActionKey()) { actionString += "YES"; } else { actionString += "NO"; } String locationString = "key location: "; int location = e.getKeyLocation(); if (location == KeyEvent.KEY_LOCATION_STANDARD) { locationString += "standard"; } else if (location == KeyEvent.KEY_LOCATION_LEFT) { locationString += "left"; } else if (location == KeyEvent.KEY_LOCATION_RIGHT) { locationString += "right"; } else if (location == KeyEvent.KEY_LOCATION_NUMPAD) { locationString += "numpad"; } else { // (location == KeyEvent.KEY_LOCATION_UNKNOWN) locationString += "unknown"; } displayArea.append(keyStatus + newline + " " + keyString + newline + " " + modString + newline + " " + actionString + newline + " " + locationString + newline); displayArea.setCaretPosition(displayArea.getDocument().getLength()); }
From source file:Main.java
private void displayInfo(KeyEvent e, String keyStatus) { // You should only rely on the key char if the event // is a key typed event. int id = e.getID(); String keyString;//from w w w . j ava 2 s. c o m if (id == KeyEvent.KEY_TYPED) { char c = e.getKeyChar(); keyString = "key character = '" + c + "'"; } else { int keyCode = e.getKeyCode(); keyString = "key code = " + keyCode + " (" + KeyEvent.getKeyText(keyCode) + ")"; } int modifiersEx = e.getModifiersEx(); String modString = "extended modifiers = " + modifiersEx; String tmpString = KeyEvent.getModifiersExText(modifiersEx); System.out.println(e.isControlDown()); if (tmpString.length() > 0) { modString += " (" + tmpString + ")"; } else { modString += " (no extended modifiers)"; } String actionString = "action key? "; if (e.isActionKey()) { actionString += "YES"; } else { actionString += "NO"; } String locationString = "key location: "; int location = e.getKeyLocation(); if (location == KeyEvent.KEY_LOCATION_STANDARD) { locationString += "standard"; } else if (location == KeyEvent.KEY_LOCATION_LEFT) { locationString += "left"; } else if (location == KeyEvent.KEY_LOCATION_RIGHT) { locationString += "right"; } else if (location == KeyEvent.KEY_LOCATION_NUMPAD) { locationString += "numpad"; } else { // (location == KeyEvent.KEY_LOCATION_UNKNOWN) locationString += "unknown"; } displayArea.append(keyStatus + newline + " " + keyString + newline + " " + modString + newline + " " + actionString + newline + " " + locationString + newline); displayArea.setCaretPosition(displayArea.getDocument().getLength()); }
From source file:Main.java
private void displayInfo(KeyEvent e, String keyStatus) { // You should only rely on the key char if the event // is a key typed event. int id = e.getID(); String keyString;/*from ww w . ja va 2 s . c o m*/ if (id == KeyEvent.KEY_TYPED) { char c = e.getKeyChar(); keyString = "key character = '" + c + "'"; } else { int keyCode = e.getKeyCode(); keyString = "key code = " + keyCode + " (" + KeyEvent.getKeyText(keyCode) + ")"; } int modifiersEx = e.getModifiersEx(); String modString = "extended modifiers = " + modifiersEx; String tmpString = KeyEvent.getModifiersExText(modifiersEx); System.out.println(e.isConsumed()); if (tmpString.length() > 0) { modString += " (" + tmpString + ")"; } else { modString += " (no extended modifiers)"; } String actionString = "action key? "; if (e.isActionKey()) { actionString += "YES"; } else { actionString += "NO"; } String locationString = "key location: "; int location = e.getKeyLocation(); if (location == KeyEvent.KEY_LOCATION_STANDARD) { locationString += "standard"; } else if (location == KeyEvent.KEY_LOCATION_LEFT) { locationString += "left"; } else if (location == KeyEvent.KEY_LOCATION_RIGHT) { locationString += "right"; } else if (location == KeyEvent.KEY_LOCATION_NUMPAD) { locationString += "numpad"; } else { // (location == KeyEvent.KEY_LOCATION_UNKNOWN) locationString += "unknown"; } displayArea.append(keyStatus + newline + " " + keyString + newline + " " + modString + newline + " " + actionString + newline + " " + locationString + newline); displayArea.setCaretPosition(displayArea.getDocument().getLength()); }
From source file:Main.java
private void displayInfo(KeyEvent e, String keyStatus) { // You should only rely on the key char if the event // is a key typed event. int id = e.getID(); String keyString;/*from www . j a v a 2 s . c o m*/ if (id == KeyEvent.KEY_TYPED) { char c = e.getKeyChar(); keyString = "key character = '" + c + "'"; } else { int keyCode = e.getKeyCode(); keyString = "key code = " + keyCode + " (" + KeyEvent.getKeyText(keyCode) + ")"; } int modifiersEx = e.getModifiersEx(); String modString = "extended modifiers = " + modifiersEx; String tmpString = KeyEvent.getModifiersExText(modifiersEx); System.out.println(e.isMetaDown()); if (tmpString.length() > 0) { modString += " (" + tmpString + ")"; } else { modString += " (no extended modifiers)"; } String actionString = "action key? "; if (e.isActionKey()) { actionString += "YES"; } else { actionString += "NO"; } String locationString = "key location: "; int location = e.getKeyLocation(); if (location == KeyEvent.KEY_LOCATION_STANDARD) { locationString += "standard"; } else if (location == KeyEvent.KEY_LOCATION_LEFT) { locationString += "left"; } else if (location == KeyEvent.KEY_LOCATION_RIGHT) { locationString += "right"; } else if (location == KeyEvent.KEY_LOCATION_NUMPAD) { locationString += "numpad"; } else { // (location == KeyEvent.KEY_LOCATION_UNKNOWN) locationString += "unknown"; } displayArea.append(keyStatus + newline + " " + keyString + newline + " " + modString + newline + " " + actionString + newline + " " + locationString + newline); displayArea.setCaretPosition(displayArea.getDocument().getLength()); }
From source file:KeyEventDemo.java
protected void displayInfo(KeyEvent e, String s) { String keyString, modString, tmpString, actionString, locationString; //You should only rely on the key char if the event //is a key typed event. int id = e.getID(); if (id == KeyEvent.KEY_TYPED) { char c = e.getKeyChar(); keyString = "key character = '" + c + "'"; } else {// ww w . j av a2 s . c om int keyCode = e.getKeyCode(); keyString = "key code = " + keyCode + " (" + KeyEvent.getKeyText(keyCode) + ")"; } int modifiers = e.getModifiersEx(); modString = "modifiers = " + modifiers; tmpString = KeyEvent.getModifiersExText(modifiers); if (tmpString.length() > 0) { modString += " (" + tmpString + ")"; } else { modString += " (no modifiers)"; } actionString = "action key? "; if (e.isActionKey()) { actionString += "YES"; } else { actionString += "NO"; } locationString = "key location: "; int location = e.getKeyLocation(); if (location == KeyEvent.KEY_LOCATION_STANDARD) { locationString += "standard"; } else if (location == KeyEvent.KEY_LOCATION_LEFT) { locationString += "left"; } else if (location == KeyEvent.KEY_LOCATION_RIGHT) { locationString += "right"; } else if (location == KeyEvent.KEY_LOCATION_NUMPAD) { locationString += "numpad"; } else { // (location == KeyEvent.KEY_LOCATION_UNKNOWN) locationString += "unknown"; } displayArea.append(s + newline + " " + keyString + newline + " " + modString + newline + " " + actionString + newline + " " + locationString + newline); displayArea.setCaretPosition(displayArea.getDocument().getLength()); }
From source file:EventTestPane.java
/** * Display keyboard events.//from w ww .j ava 2 s .c o m * * Note that there are three distinct types of key events, and that key * events are reported by key code and/or Unicode character. KEY_PRESSED and * KEY_RELEASED events are generated for all key strokes. KEY_TYPED events * are only generated when a key stroke produces a Unicode character; these * events do not report a key code. If isActionKey() returns true, then the * key event reports only a key code, because the key that was pressed or * released (such as a function key) has no corresponding Unicode character. * Key codes can be interpreted by using the many VK_ constants defined by * the KeyEvent class, or they can be converted to strings using the static * getKeyText() method as we do here. */ public void processKeyEvent(KeyEvent e) { String eventtype, modifiers, code, character; switch (e.getID()) { case KeyEvent.KEY_PRESSED: eventtype = "KEY_PRESSED"; break; case KeyEvent.KEY_RELEASED: eventtype = "KEY_RELEASED"; break; case KeyEvent.KEY_TYPED: eventtype = "KEY_TYPED"; break; default: eventtype = "UNKNOWN"; } // Convert the list of modifier keys to a string modifiers = KeyEvent.getKeyModifiersText(e.getModifiers()); // Get string and numeric versions of the key code, if any. if (e.getID() == KeyEvent.KEY_TYPED) code = ""; else code = "Code=" + KeyEvent.getKeyText(e.getKeyCode()) + " (" + e.getKeyCode() + ")"; // Get string and numeric versions of the Unicode character, if any. if (e.isActionKey()) character = ""; else character = "Character=" + e.getKeyChar() + " (Unicode=" + ((int) e.getKeyChar()) + ")"; // Display it all. showLine(eventtype + ": " + modifiers + " " + code + " " + character); }
From source file:events.KeyEventDemo.java
private void displayInfo(KeyEvent e, String keyStatus) { //You should only rely on the key char if the event //is a key typed event. int id = e.getID(); String keyString;// www. j a va 2 s .co m if (id == KeyEvent.KEY_TYPED) { char c = e.getKeyChar(); keyString = "key character = '" + c + "'"; } else { int keyCode = e.getKeyCode(); keyString = "key code = " + keyCode + " (" + KeyEvent.getKeyText(keyCode) + ")"; } int modifiersEx = e.getModifiersEx(); String modString = "extended modifiers = " + modifiersEx; String tmpString = KeyEvent.getModifiersExText(modifiersEx); if (tmpString.length() > 0) { modString += " (" + tmpString + ")"; } else { modString += " (no extended modifiers)"; } String actionString = "action key? "; if (e.isActionKey()) { actionString += "YES"; } else { actionString += "NO"; } String locationString = "key location: "; int location = e.getKeyLocation(); if (location == KeyEvent.KEY_LOCATION_STANDARD) { locationString += "standard"; } else if (location == KeyEvent.KEY_LOCATION_LEFT) { locationString += "left"; } else if (location == KeyEvent.KEY_LOCATION_RIGHT) { locationString += "right"; } else if (location == KeyEvent.KEY_LOCATION_NUMPAD) { locationString += "numpad"; } else { // (location == KeyEvent.KEY_LOCATION_UNKNOWN) locationString += "unknown"; } displayArea.append(keyStatus + newline + " " + keyString + newline + " " + modString + newline + " " + actionString + newline + " " + locationString + newline); displayArea.setCaretPosition(displayArea.getDocument().getLength()); }
From source file:Filter3dTest.java
/** * Gets the name of a key code. */ public static String getKeyName(int keyCode) { return KeyEvent.getKeyText(keyCode); }