本文整理匯總了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;
}
}
示例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();
}
示例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
}
示例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;
}
}
示例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();
}
示例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;
}
}
示例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);
}
示例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 );
}
示例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();
}
}
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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 );
}
示例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;
}
}