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

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

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

KeyEvent.getID介绍

暂无

代码示例

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

public class MyFrame extends JFrame {    
  private class MyDispatcher implements KeyEventDispatcher {
    @Override
    public boolean dispatchKeyEvent(KeyEvent e) {
      if (e.getID() == KeyEvent.KEY_PRESSED) {
        System.out.println("tester");
      } else if (e.getID() == KeyEvent.KEY_RELEASED) {
        System.out.println("2test2");
      } else if (e.getID() == KeyEvent.KEY_TYPED) {
        System.out.println("3test3");
      }
      return false;
    }
  }
  public MyFrame() {
    add(new JTextField());
    System.out.println("test");
    KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    manager.addKeyEventDispatcher(new MyDispatcher());
  }

  public static void main(String[] args) {
    MyFrame f = new MyFrame();
    f.pack();
    f.setVisible(true);
  }
}

代码示例来源:origin: groovy/groovy-core

protected void processKeyEvent(KeyEvent e) {
  super.processKeyEvent(e);
  //  Handle release of Insert key to toggle overtype/insert mode
  //  unless a modifier is active (eg Shift+Insert for paste or
  //  Ctrl+Insert for Copy)
  if (e.getID() == KeyEvent.KEY_RELEASED &&
      e.getKeyCode() == KeyEvent.VK_INSERT &&
      e.getModifiersEx() == 0) {
    setOvertypeMode(!isOvertypeMode());
  }
}

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

@Override
 public boolean dispatchKeyEvent(KeyEvent e) {
  final KeyStroke stroke;
  if (e.getID() == KeyEvent.KEY_RELEASED) {
   stroke = KeyStroke.getKeyStrokeForEvent(e);
   if (!StringHelper.isCloseKeyStroke(stroke) && stroke.getKeyCode() != KeyEvent.VK_ENTER) {
    return true;
   }
  } else if (e.getID() == KeyEvent.KEY_TYPED) {
   stroke = KeyStroke.getKeyStrokeForEvent(e);
  } else {
   return true;
  }
  if (!processor.process(stroke)) {
   KeyboardFocusManager.getCurrentKeyboardFocusManager().removeKeyEventDispatcher(this);
   loop.exit();
  }
  return true;
 }
});

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

protected boolean matches(KeyEvent e, boolean ignoreModifiers)
{
  if (NOT_SET.equals(this))
  {
    return false;
  }
  int keyCode = e.getExtendedKeyCode();
  int modifiers = e.getModifiersEx() & KEYBOARD_MODIFIER_MASK;
  Integer mf = getModifierForKeyCode(keyCode);
  if (mf != null)
  {
    modifiers |= mf;
    keyCode = KeyEvent.VK_UNDEFINED;
  }
  if (e.getID() == KeyEvent.KEY_RELEASED && keyCode != KeyEvent.VK_UNDEFINED)
  {
    return this.keyCode == keyCode;
  }
  if (ignoreModifiers && keyCode != KeyEvent.VK_UNDEFINED)
  {
    return this.keyCode == keyCode;
  }
  return this.keyCode == keyCode && this.modifiers == modifiers;
}

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

if (e.getID() == KeyEvent.KEY_PRESSED
    && commandHistory.size() > 0
    && (this.hasFocus() || focusNotNeeded)

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

e.getID() == KeyEvent.KEY_PRESSED)) {
switch (e.getKeyCode()) {
  case KeyEvent.VK_RIGHT:

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

e.getID() == KeyEvent.KEY_PRESSED)) {
switch (e.getKeyCode()) {
  case KeyEvent.VK_RIGHT:

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

/**
 * Process this key event in addition to the key events obtained from the
 * component we're attached to.
 * @param ke a key event to process.
 */
public void processKeyEvent(KeyEvent ke) {
  if (!isEnabled()) {
    return ;
  }
  if (searchPanel != null) {
    searchTextField.setCaretPosition(searchTextField.getText().length());
    searchTextField.processKeyEvent(ke);
  } else {
    switch(ke.getID()) {
      case KeyEvent.KEY_PRESSED:
        quickSearchKeyAdapter.keyPressed(ke);
        break;
      case KeyEvent.KEY_RELEASED:
        quickSearchKeyAdapter.keyReleased(ke);
        break;
      case KeyEvent.KEY_TYPED:
        quickSearchKeyAdapter.keyTyped(ke);
        break;
    }
  }
}

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

@Override
  public boolean dispatchKeyEvent(KeyEvent e) {
    if (e.getKeyCode() == KeyEvent.VK_CONTROL) {
      if (e.getID() == KeyEvent.KEY_PRESSED) {
        return handleKeyPressed();
      } else {
        return handleKeyReleased();
      }
    }
    return false;
  }
};

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

KeyboardFocusManager kfm = DefaultKeyboardFocusManager.getCurrentKeyboardFocusManager();
kfm.addKeyEventDispatcher(new KeyEventDispatcher() {
  @Override
  public boolean dispatchKeyEvent(KeyEvent e) {
    if (DefaultKeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner() == jfxPanel) {
      if (e.getID() == KeyEvent.KEY_TYPED && e.getKeyChar() == 10) {
        e.setKeyChar((char) 13);
      }
    }
    return false;
  }
});

代码示例来源:origin: net.sf.squirrel-sql.thirdpary-non-maven/openide

public void processKeyEvent(java.awt.event.KeyEvent ke) {
  super.processKeyEvent(ke);
  if ((ke.getKeyCode() == ke.VK_ENTER || ke.getKeyCode() == ke.VK_ESCAPE) 
    && ke.getID() == ke.KEY_PRESSED) {
    RadioInplaceEditor.this.fireActionPerformed(new ActionEvent(this, 
      ActionEvent.ACTION_PERFORMED, 
      ke.getKeyCode() == ke.VK_ENTER ? COMMAND_SUCCESS : 
        COMMAND_FAILURE));
  }
}

代码示例来源:origin: otros-systems/otroslogviewer

@Override
 public boolean postProcessKeyEvent(KeyEvent e) {
  if (e.getID() == KeyEvent.KEY_PRESSED) {
   if (e.getKeyCode() == keyCode && modifiers == e.getModifiers()) {
    component.requestFocus();
    return true;
   }
  }

  return false;
 }
}

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

@Override
public boolean dispatchKeyEvent(KeyEvent e) {
  if (textChangeAcceleratorAction.shouldChangeTextOnEvent(e)) {
    if (e.getID() == KeyEvent.KEY_PRESSED) {
      replaceComponentText();
    }
    return true;
  }
  return false;
}

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

/** Overridden to fire COMMAND_FAILURE on Escape */
@Override
public void processKeyEvent(KeyEvent ke) {
  super.processKeyEvent(ke);
  if ((ke.getID() == ke.KEY_PRESSED) && (ke.getKeyCode() == ke.VK_ESCAPE)) {
    setActionCommand(COMMAND_FAILURE);
    fireActionEvent();
  }
}

代码示例来源:origin: org.codehaus.groovy/groovy-console

protected void processKeyEvent(KeyEvent e) {
  super.processKeyEvent(e);
  //  Handle release of Insert key to toggle overtype/insert mode
  //  unless a modifier is active (eg Shift+Insert for paste or
  //  Ctrl+Insert for Copy)
  if (e.getID() == KeyEvent.KEY_RELEASED &&
      e.getKeyCode() == KeyEvent.VK_INSERT &&
      e.getModifiersEx() == 0) {
    setOvertypeMode(!isOvertypeMode());
  }
}

代码示例来源:origin: eu.mihosoft.vrl/vrl

/**
   * Constructor.
   * @param k the key event
   */
  public AbstractKeyEvent(KeyEvent k){
//        setSource((Component) k.getSource());
    setID(k.getID());
    setWhen(k.getWhen());
    setModifiers(k.getModifiers());
    setKeyCode(k.getKeyCode());
    setKeyChar(k.getKeyChar());
  }

代码示例来源:origin: robo-code/robocode

public void serialize(RbSerializer serializer, ByteBuffer buffer, Object object) {
  KeyReleasedEvent obj = (KeyReleasedEvent) object;
  java.awt.event.KeyEvent src = obj.getSourceEvent();
  serializer.serialize(buffer, src.getKeyChar());
  serializer.serialize(buffer, src.getKeyCode());
  serializer.serialize(buffer, src.getKeyLocation());
  serializer.serialize(buffer, src.getID());
  serializer.serialize(buffer, src.getModifiersEx());
  serializer.serialize(buffer, src.getWhen());
}

代码示例来源:origin: robo-code/robocode

public void serialize(RbSerializer serializer, ByteBuffer buffer, Object object) {
  KeyPressedEvent obj = (KeyPressedEvent) object;
  java.awt.event.KeyEvent src = obj.getSourceEvent();
  serializer.serialize(buffer, src.getKeyChar());
  serializer.serialize(buffer, src.getKeyCode());
  serializer.serialize(buffer, src.getKeyLocation());
  serializer.serialize(buffer, src.getID());
  serializer.serialize(buffer, src.getModifiersEx());
  serializer.serialize(buffer, src.getWhen());
}

代码示例来源:origin: robo-code/robocode

public void serialize(RbSerializer serializer, ByteBuffer buffer, Object object) {
  KeyTypedEvent obj = (KeyTypedEvent) object;
  java.awt.event.KeyEvent src = obj.getSourceEvent();
  serializer.serialize(buffer, src.getKeyChar());
  serializer.serialize(buffer, src.getKeyCode());
  serializer.serialize(buffer, src.getKeyLocation());
  serializer.serialize(buffer, src.getID());
  serializer.serialize(buffer, src.getModifiersEx());
  serializer.serialize(buffer, src.getWhen());
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-cnd-completion

@Override
public void processKeyEvent(KeyEvent evt) {
  if (evt.getID() == KeyEvent.KEY_TYPED) {
    JTextComponent component = (JTextComponent) evt.getSource();
    int caretOffset = component.getSelectionEnd();
    final int len = caretOffset - substitutionOffset;
    if (len < 0) {
      Completion.get().hideDocumentation();
      Completion.get().hideCompletion();
    }
  }
}

相关文章