List of usage examples for java.awt.event KeyEvent getModifiersEx
public int getModifiersEx()
From source file:KeyTest.java
public static void main(String args[]) { JFrame frame = new JFrame("Key Listener"); Container contentPane = frame.getContentPane(); KeyListener listener = new KeyListener() { public void keyPressed(KeyEvent e) { dumpInfo("Pressed", e); }//from w w w . j ava 2 s . co m public void keyReleased(KeyEvent e) { dumpInfo("Released", e); } public void keyTyped(KeyEvent e) { dumpInfo("Typed", e); } private void dumpInfo(String s, KeyEvent e) { System.out.println(s); int code = e.getKeyCode(); System.out.println("\tCode: " + KeyEvent.getKeyText(code)); System.out.println("\tChar: " + e.getKeyChar()); int mods = e.getModifiersEx(); System.out.println("\tMods: " + KeyEvent.getModifiersExText(mods)); System.out.println("\tLocation: " + location(e.getKeyLocation())); System.out.println("\tAction? " + e.isActionKey()); } private String location(int location) { switch (location) { case KeyEvent.KEY_LOCATION_LEFT: return "Left"; case KeyEvent.KEY_LOCATION_RIGHT: return "Right"; case KeyEvent.KEY_LOCATION_NUMPAD: return "NumPad"; case KeyEvent.KEY_LOCATION_STANDARD: return "Standard"; case KeyEvent.KEY_LOCATION_UNKNOWN: default: return "Unknown"; } } }; JTextField text = new JTextField(); text.addKeyListener(listener); contentPane.add(text, BorderLayout.NORTH); frame.pack(); frame.show(); }
From source file:Main.java
public static void main(String[] args) { JFrame aWindow = new JFrame(); aWindow.setBounds(50, 100, 300, 300); aWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextField typingArea = new JTextField(20); typingArea.addKeyListener(new KeyListener() { /** Handle the key typed event from the text field. */ public void keyTyped(KeyEvent e) { displayInfo(e, "KEY TYPED: "); }/* w w w . jav a 2 s. c o m*/ /** Handle the key pressed event from the text field. */ public void keyPressed(KeyEvent e) { displayInfo(e, "KEY PRESSED: "); } /** Handle the key released event from the text field. */ public void keyReleased(KeyEvent e) { displayInfo(e, "KEY RELEASED: "); } protected void displayInfo(KeyEvent e, String s) { String keyString, modString, tmpString, actionString, locationString; int id = e.getID(); 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 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"; } System.out.println(keyString); System.out.println(modString); System.out.println(actionString); System.out.println(locationString); } }); aWindow.add(typingArea); aWindow.setVisible(true); }
From source file:de.codesourcery.jasm16.ide.ui.viewcontainers.EditorContainer.java
public static final void addEditorCloseKeyListener(Component comp, final IEditorView view) { comp.addKeyListener(new KeyAdapter() { public void keyReleased(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_W && (e.getModifiersEx() & KeyEvent.CTRL_DOWN_MASK) != 0) { System.out.println("*** Closing editor " + view + " ***"); if (view.hasViewContainer()) { view.getViewContainer().disposeView(view); } else { view.dispose();/*from w w w . j av a 2 s. co m*/ } } } }); }
From source file:Main.java
private void displayInfo(KeyEvent e, String keyStatus) { int id = e.getID(); String keyString;// w w w. j av a2s. co m 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"; } System.out.println(keyStatus + "\n" + modString + "\n" + actionString + "\n"); }
From source file:com.github.fritaly.dualcommander.TabbedPane.java
@Override public void keyPressed(KeyEvent e) { if (e.getSource() == getSelectedComponent()) { final boolean metaDown = (e.getModifiersEx() | KeyEvent.META_DOWN_MASK) == KeyEvent.META_DOWN_MASK; if ((e.getKeyCode() == KeyEvent.VK_T) && metaDown) { // Create a new tab and set to focus on it setSelectedComponent(addBrowserTab(getActiveBrowser().getDirectory())); } else if ((e.getKeyCode() == KeyEvent.VK_W) && metaDown) { if (getTabCount() > 1) { // Close the current tab (only if not the last one) closeActiveBrowserTab(); }//from ww w. j ava 2s . c om } else if ((e.getKeyCode() >= KeyEvent.VK_1) && (e.getKeyCode() <= KeyEvent.VK_9) && metaDown) { final int index = e.getKeyCode() - KeyEvent.VK_1; if (index <= getTabCount() - 1) { setSelectedIndex(index); } } else { // Propagate event to our listeners processKeyEvent(new KeyEvent(this, e.getID(), e.getWhen(), e.getModifiers(), e.getKeyCode(), e.getKeyChar(), e.getKeyLocation())); } } }
From source file:com.cburch.draw.tools.LineTool.java
@Override public void keyPressed(Canvas canvas, KeyEvent e) { int code = e.getKeyCode(); if (active && (code == KeyEvent.VK_SHIFT || code == KeyEvent.VK_CONTROL)) { updateMouse(canvas, lastMouseX, lastMouseY, e.getModifiersEx()); }/*www .j a v a2 s . co m*/ }
From source file:Main.java
private void displayInfo(KeyEvent e, String keyStatus) { int id = e.getID(); String keyString;// www . j av a2 s . c om 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:Main.java
private void displayInfo(KeyEvent e, String keyStatus) { int id = e.getID(); String keyString;/*from w w w .jav a 2s . c o m*/ if (id == KeyEvent.KEY_PRESSED) { 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:Main.java
private void displayInfo(KeyEvent e, String keyStatus) { int id = e.getID(); String keyString;/*from w w w . ja va 2 s . c o m*/ if (id == KeyEvent.KEY_RELEASED) { 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:de.codesourcery.jasm16.ide.ui.viewcontainers.EditorContainer.java
private JPanel createPanel() { final JPanel result = new JPanel(); result.setLayout(new GridBagLayout()); GridBagConstraints cnstrs = constraints(0, 0, true, true, GridBagConstraints.BOTH); setColors(result);/* w ww . j av a 2 s . com*/ tabbedPane.setBackground(Color.WHITE); tabbedPane.setForeground(Color.black); result.add(tabbedPane, cnstrs); if (getViewContainer().getMenuManager() != null) { getViewContainer().getMenuManager().addEntry(saveCurrent); } tabbedPane.addChangeListener(changeListener); tabbedPane.addKeyListener(new KeyAdapter() { public void keyReleased(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_W && (e.getModifiersEx() & KeyEvent.CTRL_DOWN_MASK) != 0) { int idx = tabbedPane.getSelectedIndex(); if (idx != -1) { disposeView(getViewForTabIndex(idx)); } } } }); return result; }