当前位置: 首页>>代码示例>>Java>>正文


Java KeyEvent.KEY_TYPED属性代码示例

本文整理汇总了Java中java.awt.event.KeyEvent.KEY_TYPED属性的典型用法代码示例。如果您正苦于以下问题:Java KeyEvent.KEY_TYPED属性的具体用法?Java KeyEvent.KEY_TYPED怎么用?Java KeyEvent.KEY_TYPED使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在java.awt.event.KeyEvent的用法示例。


在下文中一共展示了KeyEvent.KEY_TYPED属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getAWTKeyStrokeForEvent

/**
 * Returns an <code>AWTKeyStroke</code> which represents the
 * stroke which generated a given <code>KeyEvent</code>.
 * <p>
 * This method obtains the keyChar from a <code>KeyTyped</code>
 * event, and the keyCode from a <code>KeyPressed</code> or
 * <code>KeyReleased</code> event. The <code>KeyEvent</code> modifiers are
 * obtained for all three types of <code>KeyEvent</code>.
 *
 * @param anEvent the <code>KeyEvent</code> from which to
 *      obtain the <code>AWTKeyStroke</code>
 * @throws NullPointerException if <code>anEvent</code> is null
 * @return the <code>AWTKeyStroke</code> that precipitated the event
 */
public static AWTKeyStroke getAWTKeyStrokeForEvent(KeyEvent anEvent) {
    int id = anEvent.getID();
    switch(id) {
      case KeyEvent.KEY_PRESSED:
      case KeyEvent.KEY_RELEASED:
        return getCachedStroke(KeyEvent.CHAR_UNDEFINED,
                               anEvent.getKeyCode(),
                               anEvent.getModifiers(),
                               (id == KeyEvent.KEY_RELEASED));
      case KeyEvent.KEY_TYPED:
        return getCachedStroke(anEvent.getKeyChar(),
                               KeyEvent.VK_UNDEFINED,
                               anEvent.getModifiers(),
                               false);
      default:
        // Invalid ID for this KeyEvent
        return null;
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:33,代码来源:AWTKeyStroke.java

示例2: dispatchKeyEvent

private void dispatchKeyEvent(final Component component, JavaAgentKeys keyToPress, int id, char c) {
    try {
        Rectangle d = EventQueueWait.exec(new Callable<Rectangle>() {
            @Override public Rectangle call() {
                return component.getBounds();
            }
        });
        ensureVisible(component.getParent(), d);
        EventQueueWait.call_noexc(component, "requestFocusInWindow");
    } catch (Exception e) {
        throw new RuntimeException("getBounds failed for " + component.getClass().getName(), e);
    }
    final KeysMap keysMap = KeysMap.findMap(keyToPress);
    if (keysMap == null) {
        return;
    }
    int m = deviceState.getModifierEx();
    int keyCode = keysMap.getCode();
    if (id == KeyEvent.KEY_TYPED) {
        keyCode = KeyEvent.VK_UNDEFINED;
    }
    dispatchEvent(new KeyEvent(component, id, System.currentTimeMillis(), m, keyCode, c));
    EventQueueWait.empty();
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:24,代码来源:EventQueueDevice.java

示例3: processKeyEvent

public void processKeyEvent (KeyEvent evt) {
    if (evt.getID() == KeyEvent.KEY_TYPED) {
        char c = evt.getKeyChar();
        JTextComponent component = (JTextComponent)evt.getSource();
        if (confirmChars == null) {
            confirmChars = getConfirmChars(component);
        }
        if (confirmChars.indexOf(c) != -1) {
            if (c != '.') {
                Completion.get().hideDocumentation();
                Completion.get().hideCompletion();
            }
            NbEditorDocument doc = (NbEditorDocument) component.getDocument ();
            try {
                defaultAction(component);
                doc.insertString(processKeyEventOffset, Character.toString(c), null);
            } catch (BadLocationException e) {
            }
            if (c == '.')
                Completion.get().showCompletion();
            evt.consume();
        } // if
    } // if
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:CompletionSupport.java

示例4: processKeyEvent

/**
 * Forwards key events directly to the input handler. This is slightly faster than using a
 * KeyListener because some Swing overhead is avoided.
 */
@Override
public void processKeyEvent(KeyEvent evt) {
	if (inputHandler == null) {
		return;
	}
	switch (evt.getID()) {
		case KeyEvent.KEY_TYPED:
			inputHandler.keyTyped(evt);
			break;
		case KeyEvent.KEY_PRESSED:
			inputHandler.keyPressed(evt);
			break;
		case KeyEvent.KEY_RELEASED:
			inputHandler.keyReleased(evt);
			break;
	}
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:21,代码来源:JEditTextArea.java

示例5: processEvent

@Override
protected void processEvent(AWTEvent evt) {
    int id = evt.getID();
    if (id != KeyEvent.KEY_TYPED) {
        super.processEvent(evt);
        return;
    }

    KeyEvent kevt = (KeyEvent) evt;
    char c = kevt.getKeyChar();

    // Digits, backspace, and delete are okay
    // Note that the minus sign is not allowed (neither is decimal)
    if (Character.isDigit(c) || (c == '\b') || (c == '\u007f')) {
        super.processEvent(evt);
        return;
    }

    Toolkit.getDefaultToolkit().beep();
    kevt.consume();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:21,代码来源:DitherTest.java

示例6: getAWTKeyStrokeForEvent

/**
 * Returns an {@code AWTKeyStroke} which represents the
 * stroke which generated a given {@code KeyEvent}.
 * <p>
 * This method obtains the keyChar from a {@code KeyTyped}
 * event, and the keyCode from a {@code KeyPressed} or
 * {@code KeyReleased} event. The {@code KeyEvent} modifiers are
 * obtained for all three types of {@code KeyEvent}.
 *
 * @param anEvent the {@code KeyEvent} from which to
 *      obtain the {@code AWTKeyStroke}
 * @throws NullPointerException if {@code anEvent} is null
 * @return the {@code AWTKeyStroke} that precipitated the event
 */
@SuppressWarnings("deprecation")
public static AWTKeyStroke getAWTKeyStrokeForEvent(KeyEvent anEvent) {
    int id = anEvent.getID();
    switch(id) {
      case KeyEvent.KEY_PRESSED:
      case KeyEvent.KEY_RELEASED:
        return getCachedStroke(KeyEvent.CHAR_UNDEFINED,
                               anEvent.getKeyCode(),
                               anEvent.getModifiers(),
                               (id == KeyEvent.KEY_RELEASED));
      case KeyEvent.KEY_TYPED:
        return getCachedStroke(anEvent.getKeyChar(),
                               KeyEvent.VK_UNDEFINED,
                               anEvent.getModifiers(),
                               false);
      default:
        // Invalid ID for this KeyEvent
        return null;
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:34,代码来源:AWTKeyStroke.java

示例7: recordRawKeyEvent

@Override public void recordRawKeyEvent(RComponent r, KeyEvent e) {
    JSONObject event = new JSONObject();
    event.put("type", "key_raw");
    int keyCode = e.getKeyCode();
    if (keyCode == KeyEvent.VK_META || keyCode == KeyEvent.VK_SHIFT || keyCode == KeyEvent.VK_ALT
            || keyCode == KeyEvent.VK_CONTROL) {
        return;
    }
    if ((e.isActionKey() || e.isControlDown() || e.isMetaDown() || e.isAltDown()) && e.getID() == KeyEvent.KEY_PRESSED) {
        String mtext = buildModifiersText(e);
        event.put("modifiersEx", mtext);
        KeysMap keysMap = KeysMap.findMap(e.getKeyCode());
        if (keysMap == KeysMap.NULL) {
            return;
        }
        String keyText;
        if (keysMap == null) {
            keyText = KeyEvent.getKeyText(e.getKeyCode());
        } else {
            keyText = keysMap.toString();
        }
        event.put("keyCode", keyText);
    } else if (e.getID() == KeyEvent.KEY_TYPED && !e.isControlDown()) {
        if (Character.isISOControl(e.getKeyChar()) && hasMapping(e.getKeyChar())) {
            event.put("keyChar", getMapping(e.getKeyChar()));
        } else {
            event.put("keyChar", "" + e.getKeyChar());
        }
    } else {
        return;
    }
    recordEvent(r, event);
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:33,代码来源:WSRecorder.java

示例8: testGlobalActionDoesNotSurviveFocusChange

public void testGlobalActionDoesNotSurviveFocusChange() throws Exception {
    myGlobalAction.setEnabled( true );
    
    final org.openide.nodes.Node n = new org.openide.nodes.AbstractNode (org.openide.nodes.Children.LEAF);
    tc.setActivatedNodes(new Node[0]);
    
    KeyEvent e = new KeyEvent( tc, KeyEvent.KEY_TYPED, 0, 0, 0 );
    assertTrue( tc.processKeyBinding( KEY_STROKE, e, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, true ) );
    assertTrue( MyContextAwareAction.globalActionWasPerformed );
    assertFalse( MyContextAwareAction.contextActionWasPerformed );
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:ContextAwareActionInTopComponentTest.java

示例9: processKeyEvent

@Override
public void processKeyEvent(KeyEvent evt) {
    if (evt.getID() == KeyEvent.KEY_TYPED) {
        if(evt.getKeyChar() == '/') { // NOI18N
            Completion.get().hideDocumentation();
            JTextComponent component = (JTextComponent)evt.getSource();
            int caretOffset = component.getSelectionEnd();
            substituteText(component, substitutionOffset, caretOffset - substitutionOffset, Character.toString(evt.getKeyChar()));
            Completion.get().showCompletion();
            evt.consume();
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:13,代码来源:SpringXMLConfigCompletionItem.java

示例10: _scanQueue

/**
 * Run through the queue to see if we got a possible match of:
 * [0] stx, [1 - (n-1)] Integers within time frame, [n]
 * @return the count of key events we can dump out to the user
 */
private int _scanQueue()
{
    StringBuilder barcode = new StringBuilder();
    ListIterator<KeyEvent> iter = queue.listIterator();

    KeyEvent first = iter.next();
    if ((first.getID() != KeyEvent.KEY_TYPED) || (first.getKeyChar() != config.stx))
        return 1;
    
    while (iter.hasNext())
    {
        KeyEvent ke = iter.next();            
        if (ke.getID() != KeyEvent.KEY_TYPED)  // only look at TYPED events
            continue;

        Character c = ke.getKeyChar();
        if (c == config.stx) // a second stx char, clear buffer before this 
            return iter.nextIndex()-1;
        
        if (c == config.etx) {
            queue.clear();
            log.log(Level.FINE, "Scanned barcode {0}", barcode);
            Messenger.sendEvent(MT.BARCODE_SCANNED, barcode.toString());
            return iter.nextIndex();  // time to dump
        }

        barcode.append(c);            
        if (barcode.length() > 20) {
            log.log(Level.FINE, "Barcode too long, ignoring");
            return iter.nextIndex(); // time to dump
        }
    }

    return 0;
}
 
开发者ID:drytoastman,项目名称:scorekeeperfrontend,代码行数:40,代码来源:BarcodeScannerWatcher.java

示例11: create

public final KeyEvent create(int id, int keyCode, char c) {
    return new KeyEvent(component, id, System.currentTimeMillis(), 0, keyCode, c,
            id != KeyEvent.KEY_TYPED ? KeyEvent.KEY_LOCATION_STANDARD : KeyEvent.KEY_LOCATION_UNKNOWN);
}
 
开发者ID:Parabot,项目名称:Parabot-317-API-Minified-OS-Scape,代码行数:4,代码来源:InternalKeyboard.java

示例12: handleJavaKeyEvent

@Override
public boolean handleJavaKeyEvent(KeyEvent e) {
    switch (e.getID()) {
       case KeyEvent.KEY_TYPED:
           if ((e.getKeyChar() == '\n') && !e.isAltDown() && !e.isControlDown()) {
                postEvent(new ActionEvent(target, ActionEvent.ACTION_PERFORMED,
                                          getText(), e.getWhen(), e.getModifiers()));
                return true;
           }
       break;
    }
    return false;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:13,代码来源:WTextFieldPeer.java

示例13: handleJavaKeyEvent

@Override
@SuppressWarnings("deprecation")
public boolean handleJavaKeyEvent(KeyEvent e) {
    switch (e.getID()) {
       case KeyEvent.KEY_TYPED:
           if ((e.getKeyChar() == '\n') && !e.isAltDown() && !e.isControlDown()) {
                postEvent(new ActionEvent(target, ActionEvent.ACTION_PERFORMED,
                                          getText(), e.getWhen(), e.getModifiers()));
                return true;
           }
       break;
    }
    return false;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:WTextFieldPeer.java

示例14: testGlobalActionSurvivedFocusChange

public void testGlobalActionSurvivedFocusChange() throws Exception {
    myGlobalAction.setEnabled( true );
    
    final org.openide.nodes.Node n = new org.openide.nodes.AbstractNode (org.openide.nodes.Children.LEAF);
    tc.setActivatedNodes(null);
    
    KeyEvent e = new KeyEvent( tc, KeyEvent.KEY_TYPED, 0, 0, 0 );
    assertTrue( tc.processKeyBinding( KEY_STROKE, e, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, true ) );
    assertTrue( MyContextAwareAction.globalActionWasPerformed );
    assertFalse( MyContextAwareAction.contextActionWasPerformed );
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:ContextAwareActionInTopComponentTest.java

示例15: dispatchCommittedText

/**
 * Dispatches committed text to a client component.
 * Called by composition window.
 *
 * @param client The component that the text should get dispatched to.
 * @param text The iterator providing access to the committed
 *        (and possible composed) text.
 * @param committedCharacterCount The number of committed characters in the text.
 */
synchronized void dispatchCommittedText(Component client,
             AttributedCharacterIterator text,
             int committedCharacterCount) {
    // note that the client is not always the current client component -
    // some host input method adapters may dispatch input method events
    // through the Java event queue, and we may have switched clients while
    // the event was in the queue.
    if (committedCharacterCount == 0
            || text.getEndIndex() <= text.getBeginIndex()) {
        return;
    }
    long time = System.currentTimeMillis();
    dispatchingCommittedText = true;
    try {
        InputMethodRequests req = client.getInputMethodRequests();
        if (req != null) {
            // active client -> send text as InputMethodEvent
            int beginIndex = text.getBeginIndex();
            AttributedCharacterIterator toBeCommitted =
                (new AttributedString(text, beginIndex, beginIndex + committedCharacterCount)).getIterator();

            InputMethodEvent inputEvent = new InputMethodEvent(
                    client,
                    InputMethodEvent.INPUT_METHOD_TEXT_CHANGED,
                    toBeCommitted,
                    committedCharacterCount,
                    null, null);

            client.dispatchEvent(inputEvent);
        } else {
            // passive client -> send text as KeyEvents
            char keyChar = text.first();
            while (committedCharacterCount-- > 0 && keyChar != CharacterIterator.DONE) {
                KeyEvent keyEvent = new KeyEvent(client, KeyEvent.KEY_TYPED,
                                             time, 0, KeyEvent.VK_UNDEFINED, keyChar);
                client.dispatchEvent(keyEvent);
                keyChar = text.next();
            }
        }
    } finally {
        dispatchingCommittedText = false;
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:52,代码来源:InputMethodContext.java


注:本文中的java.awt.event.KeyEvent.KEY_TYPED属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。