List of usage examples for java.awt.event KeyEvent KEY_TYPED
int KEY_TYPED
To view the source code for java.awt.event KeyEvent KEY_TYPED.
Click Source Link
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 {// w ww.j a va 2s . c o m 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 www. j av a 2 s .co 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;// w w w. j a 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); 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:PVGraph.java
public PVGraph(Calendar date, int initialViewIndex) { super(WINDOW_TITLE_PREFIX); this.date = date; synchronized (graphs) { graphs.add(this); }//from w ww. j av a2 s .co m views = new PVGraphView[4]; views[DAY_VIEW_INDEX] = new DayView(); views[MONTH_VIEW_INDEX] = new MonthView(); views[YEAR_VIEW_INDEX] = new YearView(); views[YEARS_VIEW_INDEX] = new YearsView(); tabPane = new JTabbedPane(); for (PVGraphView v : views) tabPane.addTab(v.getTabLabel(), v.makePanel()); tabPane.setSelectedIndex(initialViewIndex); setContentPane(tabPane); pack(); try { java.net.URL url = getClass().getResource("sun.png"); if (url != null) setIconImage(ImageIO.read(url)); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } ; setVisible(true); KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(new KeyEventDispatcher() { public boolean dispatchKeyEvent(KeyEvent ke) { Object src = ke.getSource(); if (src instanceof JComponent && ((JComponent) src).getRootPane().getContentPane() == tabPane) { if (ke.getID() == KeyEvent.KEY_TYPED) { switch (ke.getKeyChar()) { case 'd': tabPane.setSelectedIndex(DAY_VIEW_INDEX); return true; case 'm': tabPane.setSelectedIndex(MONTH_VIEW_INDEX); return true; case 'N' - 0x40: new PVGraph((Calendar) PVGraph.this.date.clone(), tabPane.getSelectedIndex()); return true; case 'Q' - 0x40: dispatchEvent(new WindowEvent(PVGraph.this, WindowEvent.WINDOW_CLOSING)); return true; case 'R' - 0x40: loadProperties(); updateView(); return true; case 'S': try { runSmatool(); updateView(); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } return true; case 'y': tabPane.setSelectedIndex(YEAR_VIEW_INDEX); return true; case 'Y': tabPane.setSelectedIndex(YEARS_VIEW_INDEX); return true; default: return views[tabPane.getSelectedIndex()].handleKey(ke.getKeyChar()); } } } return false; } }); }
From source file:com.jcraft.weirdx.DDXWindowImp.java
public void processKeyEvent(KeyEvent e) { int id = e.getID(); if (id == KeyEvent.KEY_PRESSED) { keyPressed(e);//ww w . j a v a 2 s. co m } else if (id == KeyEvent.KEY_RELEASED) { keyReleased(e); } else if (id == KeyEvent.KEY_TYPED) { keyTyped(e); } e.consume(); // ?? }
From source file:org.eclipse.jubula.rc.swing.driver.RobotAwtImpl.java
/** * {@inheritDoc}/*from w w w .ja va 2s .c o m*/ */ public void type(Object graphicsComponent, char character) throws RobotException { Validate.notNull(graphicsComponent, "The graphic component must not be null"); //$NON-NLS-1$ try { int modifier = 0; Component component = (Component) graphicsComponent; KeyEvent ke = new KeyEvent(component, KeyEvent.KEY_PRESSED, System.currentTimeMillis(), modifier, KeyEvent.VK_UNDEFINED, character); Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(ke); ke = new KeyEvent(component, KeyEvent.KEY_TYPED, System.currentTimeMillis(), modifier, KeyEvent.VK_UNDEFINED, character); Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(ke); IRobotEventConfirmer confirmer = m_interceptor .intercept(new InterceptorOptions(new long[] { AWTEvent.KEY_EVENT_MASK })); ke = new KeyEvent(component, KeyEvent.KEY_RELEASED, System.currentTimeMillis(), modifier, KeyEvent.VK_UNDEFINED, character); Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(ke); confirmer.waitToConfirm(component, new DefaultAwtEventMatcher(KeyEvent.KEY_RELEASED)); } catch (AWTError awte) { log.error(awte); throw new RobotException(awte); } catch (SecurityException se) { log.error(se); throw new RobotException(se); } }
From source file:org.wings.plaf.css.FrameCG.java
private void appendStrokes(StringBuilder builder, SComponent component, int condition, InputMap inputMap) { KeyStroke[] keyStrokes = inputMap.keys(); if (keyStrokes != null) { for (int i = 0; i < keyStrokes.length; i++) { KeyStroke keyStroke = keyStrokes[i]; Object binding = inputMap.get(keyStroke); switch (keyStroke.getKeyEventType()) { case KeyEvent.KEY_PRESSED: builder.append("kss.push(new ks('"); builder.append(component.getName()); builder.append("',"); builder.append(//from w ww. jav a2s . co m condition == SComponent.WHEN_FOCUSED_OR_ANCESTOR_OF_FOCUSED_COMPONENT ? "!0" : "!1"); builder.append(",'"); builder.append(binding); builder.append("',"); builder.append(keyStroke.getKeyCode()); builder.append(','); builder.append((keyStroke.getModifiers() & InputEvent.SHIFT_DOWN_MASK) != 0 ? "!0" : "!1"); builder.append(','); builder.append((keyStroke.getModifiers() & InputEvent.CTRL_DOWN_MASK) != 0 ? "!0" : "!1"); builder.append(','); builder.append((keyStroke.getModifiers() & InputEvent.ALT_DOWN_MASK) != 0 ? "!0" : "!1"); builder.append("));\n"); break; case KeyEvent.KEY_TYPED: break; case KeyEvent.KEY_RELEASED: break; } } } }
From source file:org.wings.plaf.css.InputMapScriptListener.java
public static void install(SComponent component) { ScriptListener[] scriptListeners = component.getScriptListeners(); for (int i = 0; i < scriptListeners.length; i++) { ScriptListener scriptListener = scriptListeners[i]; if (scriptListener instanceof InputMapScriptListener) component.removeScriptListener(scriptListener); }//from w w w.ja v a2 s. co m InputMap inputMap = component.getInputMap(); if (inputMap.size() == 0) return; // we're done StringBuffer pressed = new StringBuffer(); StringBuffer typed = new StringBuffer(); StringBuffer released = new StringBuffer(); KeyStroke[] keyStrokes = inputMap.keys(); for (int i = 0; i < keyStrokes.length; i++) { KeyStroke keyStroke = keyStrokes[i]; Object binding = inputMap.get(keyStroke); /* writeMatch(typed, keyStroke); writeRequest(typed, binding); */ switch (keyStroke.getKeyEventType()) { case KeyEvent.KEY_PRESSED: writeMatch(pressed, keyStroke); writeRequest(pressed, binding); break; case KeyEvent.KEY_TYPED: writeMatch(typed, keyStroke); writeRequest(typed, binding); log.debug("typed binding = " + binding); break; case KeyEvent.KEY_RELEASED: writeMatch(released, keyStroke); writeRequest(released, binding); log.debug("released binding = " + binding); break; } } if (pressed.length() > 0) component.addScriptListener( new InputMapScriptListener("onkeydown", "return pressed_" + component.getName() + "(event)", "function pressed_" + component.getName() + "(event) {\n " + "event = getEvent(event);\n " + pressed.toString() + " return true;\n}\n")); if (typed.length() > 0) component.addScriptListener( new InputMapScriptListener("onkeypress", "return typed_" + component.getName() + "(event)", "function typed_" + component.getName() + "(event) {\n " + "event = getEvent(event);\n " + typed.toString() + " return true;\n}\n")); if (released.length() > 0) component.addScriptListener( new InputMapScriptListener("onkeyup", "return released_" + component.getName() + "(event)", "function released_" + component.getName() + "(event) {\n" + "event = getEvent(event);\n " + released.toString() + " return true;\n}\n")); }
From source file:org.wings.plaf.css.InputMapScriptListener.java
public static void installToFrame(SFrame frame, SComponent component) { InputMap inputMap = component.getInputMap(SComponent.WHEN_IN_FOCUSED_FRAME); StringBuffer pressed = new StringBuffer(); StringBuffer typed = new StringBuffer(); StringBuffer released = new StringBuffer(); KeyStroke[] keyStrokes = inputMap.keys(); for (int i = 0; i < keyStrokes.length; i++) { KeyStroke keyStroke = keyStrokes[i]; Object binding = inputMap.get(keyStroke); /*//from w w w . j a v a 2 s. c o m writeMatch(typed, keyStroke); writeRequest(typed, binding); */ switch (keyStroke.getKeyEventType()) { case KeyEvent.KEY_PRESSED: writeMatch(pressed, keyStroke); writeRequestForFrame(pressed, binding, component.getName()); break; case KeyEvent.KEY_TYPED: writeMatch(typed, keyStroke); writeRequestForFrame(typed, binding, component.getName()); log.debug("typed binding = " + binding); break; case KeyEvent.KEY_RELEASED: writeMatch(released, keyStroke); writeRequestForFrame(released, binding, component.getName()); log.debug("released binding = " + binding); break; } } if (pressed.length() > 0) frame.addScriptListener( new InputMapScriptListener("onkeydown", "pressed_frame_" + component.getName() + "(event)", "function pressed_frame_" + component.getName() + "(event) {\n " + "event = getEvent(event);\n " + pressed.toString() + " return true;\n}\n")); if (typed.length() > 0) frame.addScriptListener( new InputMapScriptListener("onkeypress", "typed_frame_" + component.getName() + "(event)", "function typed_frame_" + component.getName() + "(event) {\n " + "event = getEvent(event);\n " + typed.toString() + " return true;\n}\n")); if (released.length() > 0) frame.addScriptListener( new InputMapScriptListener("onkeyup", "released_frame_" + component.getName() + "(event)", "function released_frame_" + component.getName() + "(event) {\n" + "event = getEvent(event);\n " + released.toString() + " return true;\n}\n")); }
From source file:view.MainWindow.java
@Override public boolean dispatchKeyEvent(KeyEvent e) { if (e.getID() == KeyEvent.KEY_PRESSED) { if (e.isControlDown()) { if (e.getKeyCode() == KeyEvent.VK_W) { closeDocument(true);/* w ww.j a va 2s . c o m*/ } else if (e.getKeyCode() == KeyEvent.VK_ADD) { workspacePanel.zoomIn(); } else if (e.getKeyCode() == KeyEvent.VK_SUBTRACT) { workspacePanel.zoomOut(); } else if (e.getKeyCode() == KeyEvent.VK_DOWN || e.getKeyCode() == KeyEvent.VK_RIGHT) { workspacePanel.pageUp(); } else if (e.getKeyCode() == KeyEvent.VK_UP || e.getKeyCode() == KeyEvent.VK_LEFT) { workspacePanel.pageDown(); } if (e.isShiftDown()) { if (e.getKeyCode() == KeyEvent.VK_S) { workspacePanel.changeCard(WorkspacePanel.CardEnum.SIGN_PANEL, true); } else if (e.getKeyCode() == KeyEvent.VK_V) { workspacePanel.changeCard(WorkspacePanel.CardEnum.VALIDATE_PANEL, true); } } } } else if (e.getID() == KeyEvent.KEY_RELEASED) { } else if (e.getID() == KeyEvent.KEY_TYPED) { } return false; }