java.awt.event.KeyEvent.getKeyChar()方法的使用及代码示例

x33g5p2x  于2022-01-23 转载在 其他  
字(5.7k)|赞(0)|评价(0)|浏览(328)

本文整理了Java中java.awt.event.KeyEvent.getKeyChar()方法的一些代码示例,展示了KeyEvent.getKeyChar()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。KeyEvent.getKeyChar()方法的具体详情如下:
包路径:java.awt.event.KeyEvent
类名称:KeyEvent
方法名:getKeyChar

KeyEvent.getKeyChar介绍

[英]Returns the character associated with the key in this event. For example, the key-typed event for shift + "a" returns the value for "A".
[中]返回与此事件中的键关联的字符。例如,shift+“a”的键类型事件返回“a”的值。

代码示例

代码示例来源:origin: JetBrains/ideavim

switch (e.getKeyChar()) {
 case ' ':
  myExOutputPanel.scrollPage();
  break;
 case KeyEvent.CHAR_UNDEFINED: {
  switch (e.getKeyCode()) {
   case KeyEvent.VK_ENTER:
    myExOutputPanel.handleEnter();

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

public void keyPressed(KeyEvent evt) {
  int code = convertAwtKey(evt.getKeyCode());
  
  // Check if key was already pressed
  if (!keyStateSet.get(code)){
    keyStateSet.set(code);
    KeyInputEvent keyEvent = new KeyInputEvent(code, evt.getKeyChar(), true, false);
    keyEvent.setTime(evt.getWhen());
    synchronized (eventQueue){
      eventQueue.add(keyEvent);
    }            
  }
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

public void keyReleased(KeyEvent evt) {
  int code = convertAwtKey(evt.getKeyCode());
  
  // Check if key was already released
  if (keyStateSet.get(code)) {
    keyStateSet.clear(code);
    KeyInputEvent keyEvent = new KeyInputEvent(code, evt.getKeyChar(), false, false);
    keyEvent.setTime(evt.getWhen());
    synchronized (eventQueue){
      eventQueue.add(keyEvent);
    }                        
  }
}

代码示例来源:origin: opensourceBIM/BIMserver

@Override
  public void keyPressed(KeyEvent e) {
    try {
      exec.getOutputStream().write(e.getKeyChar());
      if (e.getKeyCode() == KeyEvent.VK_ENTER) {
        exec.getOutputStream().flush();
      }
    } catch (IOException e2) {
      e2.printStackTrace();
    }
  }
});

代码示例来源:origin: jbox2d/jbox2d

@Override
public void keyReleased(KeyEvent arg0) {
 controller.queueKeyReleased(arg0.getKeyChar(), arg0.getKeyCode());
}

代码示例来源:origin: RaiMan/SikuliX2

private void myKeyReleased(KeyEvent e) {
 int code = e.getKeyCode();
 if (e.CHAR_UNDEFINED != e.getKeyChar()) {
 } else {
  String cName = keyReleasedHandler(code, 1);
  log.trace("keyReleased: %s (%d) %s %s %s", e.getKeyText(code), code, cName,
      activeSides[activeSide], activeSides[activeSideSaved]);
 }
}

代码示例来源:origin: org.netbeans.api/org-openide-awt

@Override
  public void keyTyped(KeyEvent e) {
    int modifiers = e.getModifiers();
    int keyCode = e.getKeyCode();
    char c = e.getKeyChar();
    //#43617 - don't eat + and -
    //#98634 - and all its duplicates dont't react to space
    if ((c == '+') || (c == '-') || (c==' ')) return; // NOI18N
    if (((modifiers > 0) && (modifiers != KeyEvent.SHIFT_MASK)) || e.isActionKey()) {
      return;
    }
    if (Character.isISOControl(c) ||
        (keyCode == KeyEvent.VK_SHIFT) ||
        (keyCode == KeyEvent.VK_ESCAPE)) return;
    displaySearchField();
    
    final KeyStroke stroke = KeyStroke.getKeyStrokeForEvent(e);
    searchTextField.setText(String.valueOf(stroke.getKeyChar()));
    e.consume();
  }
}

代码示例来源:origin: jbox2d/jbox2d

@Override
 public void keyPressed(KeyEvent arg0) {
  char c = arg0.getKeyChar();
  controller.queueKeyPressed(c, arg0.getKeyCode());
  switch (c) {
   case '[':
    controller.lastTest();
    break;
   case ']':
    controller.nextTest();
    break;
   case 'r':
    controller.reset();
    break;
   case ' ':
    controller.queueLaunchBomb();
    break;
   case 'p':
    controller.queuePause();
    break;
  }
 }
});

代码示例来源:origin: winder/Universal-G-Code-Sender

double DELTA_SIZE = 0.1;
switch(ke.getKeyCode()) {
  case KeyEvent.VK_UP:
    this.eye.y+=DELTA_SIZE;
switch(ke.getKeyChar()) {
  case 'p':
    this.eye.z+=DELTA_SIZE;

代码示例来源:origin: openimaj/openimaj

@Override
public void keyPressed(KeyEvent e) {
  if (e.getKeyChar() == 'l') {
    direction = Direction.LEFT;
  }
  else if (e.getKeyChar() == 'r') {
    direction = Direction.RIGHT;
  }
  else if (e.getKeyCode() == KeyEvent.VK_SPACE) {
    direction = Direction.MIDDLE;
  }
}

代码示例来源:origin: org.openimaj/sandbox

@Override
public void keyPressed(KeyEvent e) {
  if (e.getKeyChar() == 'l') {
    direction = Direction.LEFT;
  }
  else if (e.getKeyChar() == 'r') {
    direction = Direction.RIGHT;
  }
  else if (e.getKeyCode() == KeyEvent.VK_SPACE) {
    direction = Direction.MIDDLE;
  }
}

代码示例来源:origin: stackoverflow.com

public void keyTyped(KeyEvent e) {
  int keyCode = e.getKeyCode();
  char keyLetter = e.getKeyChar();
  if(Character.*isLetterOrDigit*(keyLetter)); // The if statement ends here 
                        // because of the ;

} // the function keyTyped ends here
else if(keyCode == KeyEvent.VK_ENTER){ // the else is not connected to the if
  dis.setWaitingforInputfalse();
}
}
}

代码示例来源:origin: stackoverflow.com

@Override
public void keyTyped(KeyEvent evt) {
  if (!Character.isDigit(evt.getKeyChar()) && !(evt.getKeyCode() == KeyEvent.VK_BACK_SPACE)) {
    evt.consume();
  }
}

代码示例来源:origin: com.googlecode.gstreamer-java/gstreamer-java

private String getKey(KeyEvent evt) {
  if (keyMap.containsKey(evt.getKeyCode())) {
    return keyMap.get(evt.getKeyCode());
  }
  return String.valueOf(evt.getKeyChar());
}
private void key(String name, KeyEvent evt) {

代码示例来源:origin: com.github.jjYBdx4IL.utils/junit4-utils

@Override
public void keyReleased(KeyEvent e) {
  log.info(e.toString());
  if (e.getKeyCode() == KeyEvent.VK_ESCAPE || e.getKeyChar() == 'q' || e.getKeyChar() == 'Q') {
    log.debug("jf.dispose()");
    jf.dispose();
  }
}

代码示例来源:origin: com.synaptix/SynaptixSwing

@Override
  public void keyReleased(KeyEvent e) {
    System.out.println(e.getKeyCode() + " " + e.getKeyChar() + " "
        + KeyEvent.getKeyText(e.getKeyCode()));
  }
}

代码示例来源:origin: com.b3dgs.lionengine/lionengine-core-awt

@Override
  public void keyReleased(KeyEvent event)
  {
    listener.keyReleased(event.getKeyCode(), event.getKeyChar());
  }
}

代码示例来源:origin: com.b3dgs.lionengine/lionengine-core-awt

@Override
public void keyPressed(KeyEvent event)
{
  listener.keyPressed(event.getKeyCode(), event.getKeyChar());
}

代码示例来源:origin: stackoverflow.com

Button a = new Button("click");
 KeyEvent e;
 e = new KeyEvent(a, 1, 20, 1, 10, 'a');
 System.out.println(""+e.getKeyChar());
 System.out.println(""+e.getKeyCode());

代码示例来源:origin: org.microemu/microemu-javase-swing

public static J2SEButton getButton(KeyEvent ev) {
  DeviceInformation inf = getDeviceInformation();
  J2SEButton button = (J2SEButton) inf.keyboardCharCodes.get(new Integer(ev.getKeyChar()));
  if (button != null) {
    return button;
  }
  return (J2SEButton) inf.keyboardKeyCodes.get(new Integer(ev.getKeyCode()));
}

相关文章