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

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

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

KeyListener.keyPressed介绍

[英]Invoked when a key has been pressed. See the class description for KeyEvent for a definition of a key pressed event.
[中]当按下某个键时调用。有关按键事件的定义,请参见KeyEvent的类描述。

代码示例

代码示例来源:origin: net.sf.nachocalendar/nachocalendar

/**
 * Notifies all registered listeners about the event.
 *
 * @param event The event to be fired
 */
private void fireKeyListenerKeyPressed(final java.awt.event.KeyEvent event) {
  if (listenerList == null) {
    return;
  }
  final Object[] listeners = listenerList.getListenerList();
  for (int i = listeners.length - 2; i >= 0; i -= 2) {
    if (listeners[i] == java.awt.event.KeyListener.class) {
      ((java.awt.event.KeyListener) listeners[i + 1]).keyPressed(event);
    }
  }
}

代码示例来源:origin: net.sf.nachocalendar/nachocalendar

/**
 * Notifies all registered listeners about the event.
 * 
 * @param event
 *            The event to be fired
 */
private void fireKeyListenerKeyPressed(final java.awt.event.KeyEvent event) {
  if (listenerList == null) {
    return;
  }
  final Object[] listeners = listenerList.getListenerList();
  for (int i = listeners.length - 2; i >= 0; i -= 2) {
    if (listeners[i] == java.awt.event.KeyListener.class) {
      ((java.awt.event.KeyListener) listeners[i + 1]).keyPressed(event);
    }
  }
}

代码示例来源:origin: sc.fiji/fiji-lib

@Override
public final void keyPressed(KeyEvent e) {
  if (isThisTool())
    listener.keyPressed(e);
}

代码示例来源:origin: xyz.cofe/docking-frames-core

public boolean keyPressed( DockElement element, KeyEvent event ){
    if( element == AbstractDockable.this ){
      for( KeyListener listener : getKeyListeners() ){
        listener.keyPressed( event );
      }
      return event.isConsumed();
    }
    else{
      return false;
    }
  }
};

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

@Override
public void keyPressed(KeyEvent evt) {
  for (KeyListener l : videoComponent.getKeyListeners()) {
    l.keyPressed(evt);
  }
}

代码示例来源:origin: brackeen/Scared

public void keyPressed(KeyEvent e) {
  KeyListener keyListener = getFocusedViewKeyListener();
  if (keyListener != null) {
    keyListener.keyPressed(e);
  }
}

代码示例来源:origin: sc.fiji/fiji-lib

@Override
public final void keyPressed(KeyEvent e) {
  if (!e.isConsumed())
    listener.keyPressed(e);
}

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

public void keyPressed(KeyEvent e) {
  for(KeyListener kl : JDateHourField.this.getKeyListeners())
    kl.keyPressed(e);
}

代码示例来源:origin: gurkenlabs/litiengine

/**
 * Execute pressed keys.
 */
private void executePressedKeys() {
 // called at the rate of the updaterate
 this.pressedKeys.forEach(key -> {
  this.keySpecificPressedConsumer.forEach(consumer -> {
   if (consumer.getKey().intValue() == key.getKeyCode()) {
    consumer.getValue().accept(key);
   }
  });
  this.keyPressedConsumer.forEach(consumer -> consumer.accept(key));
  this.keyListeners.forEach(listener -> listener.keyPressed(key));
 });
}

代码示例来源:origin: jzy3d/jzy3d-api

@Override
public void keyPressed(KeyEvent ke) {
  keyListener.keyPressed(convertEvent(ke, java.awt.event.KeyEvent.KEY_PRESSED));
}

代码示例来源:origin: mikaelhg/openblocks

public void processKeyPressed(KeyEvent e) {
  for (KeyListener l : this.getKeyListeners()) {
    l.keyPressed(e);
  }
}

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

public void handleKeyEvent(@NotNull KeyEvent e) {
 final int id = e.getID();
 if (id == KeyEvent.KEY_PRESSED) {
  for (KeyListener keyListener : myCustomKeyListeners) {
   keyListener.keyPressed(e);
  }
 } else if (id == KeyEvent.KEY_TYPED) {
  for (KeyListener keyListener : myCustomKeyListeners) {
   keyListener.keyTyped(e);
  }
 }
}

代码示例来源:origin: com.eas.platypus/platypus-js-forms

@Override
public void keyPressed(KeyEvent e) {
  KeyListener[] kls = getKeyListeners();
  if (kls != null) {
    e.setSource(ModelComponentDecorator.this);
    for (KeyListener kl : kls) {
      kl.keyPressed(e);
    }
  }
}

代码示例来源:origin: net.imagej/ij

public void keyPressed(KeyEvent e) {
  int key = e.getKeyCode();
  if (key==KeyEvent.VK_BACK_SPACE || key==KeyEvent.VK_DELETE)
    clearSelection();
  else if (key==KeyEvent.VK_UP)
    scroll(-1);
  else if (key==KeyEvent.VK_DOWN)
    scroll(1);
  else if (keyListener!=null&&key!=KeyEvent.VK_S&& key!=KeyEvent.VK_C && key!=KeyEvent.VK_X
  && key!=KeyEvent.VK_A && key!=KeyEvent.VK_F && key!=KeyEvent.VK_G)
    keyListener.keyPressed(e);
}

代码示例来源:origin: imagej/ImageJA

public void keyPressed(KeyEvent e) {
  int key = e.getKeyCode();
  if (key==KeyEvent.VK_BACK_SPACE || key==KeyEvent.VK_DELETE)
    clearSelection();
  else if (key==KeyEvent.VK_UP)
    scroll(-1);
  else if (key==KeyEvent.VK_DOWN)
    scroll(1);
  else if (keyListener!=null&&key!=KeyEvent.VK_S&& key!=KeyEvent.VK_C && key!=KeyEvent.VK_X
  && key!=KeyEvent.VK_A && key!=KeyEvent.VK_F && key!=KeyEvent.VK_G)
    keyListener.keyPressed(e);
}

代码示例来源:origin: org.swinglabs.swingx/swingx-core

@Override
  public void eventDispatched(AWTEvent aWTEvent) {
    if (aWTEvent instanceof KeyEvent) {
      KeyEvent evt = (KeyEvent)aWTEvent;
      for (KeyListener kl : getKeyListeners()) {
        int id = aWTEvent.getID();
        switch (id) {
          case KeyEvent.KEY_PRESSED:
            kl.keyPressed(evt);
            break;
          case KeyEvent.KEY_RELEASED:
            kl.keyReleased(evt);
            break;
          case KeyEvent.KEY_TYPED:
            kl.keyTyped(evt);
            break;
          default:
            System.err.println("Unhandled Key ID: " + id);    
        }
      }
    }
  }
};

代码示例来源:origin: org.codehaus.jtstand/jtstand-desktop

public void eventDispatched(AWTEvent aWTEvent) {
    if (aWTEvent instanceof KeyEvent) {
      KeyEvent evt = (KeyEvent)aWTEvent;
      for (KeyListener kl : getKeyListeners()) {
        int id = aWTEvent.getID();
        switch (id) {
          case KeyEvent.KEY_PRESSED:
            kl.keyPressed(evt);
            break;
          case KeyEvent.KEY_RELEASED:
            kl.keyReleased(evt);
            break;
          case KeyEvent.KEY_TYPED:
            kl.keyTyped(evt);
            break;
          default:
            System.err.println("Unhandled Key ID: " + id);    
        }
      }
    }
  }
};

代码示例来源:origin: org.swinglabs.swingx/swingx-all

@Override
  public void eventDispatched(AWTEvent aWTEvent) {
    if (aWTEvent instanceof KeyEvent) {
      KeyEvent evt = (KeyEvent)aWTEvent;
      for (KeyListener kl : getKeyListeners()) {
        int id = aWTEvent.getID();
        switch (id) {
          case KeyEvent.KEY_PRESSED:
            kl.keyPressed(evt);
            break;
          case KeyEvent.KEY_RELEASED:
            kl.keyReleased(evt);
            break;
          case KeyEvent.KEY_TYPED:
            kl.keyTyped(evt);
            break;
          default:
            System.err.println("Unhandled Key ID: " + id);    
        }
      }
    }
  }
};

代码示例来源:origin: elki-project/elki

@Override
public void keyPressed(KeyEvent e) {
 if((e.getModifiersEx() & KeyEvent.CTRL_DOWN_MASK) != 0) {
  if(e.getKeyCode() == KeyEvent.VK_SPACE //
    || e.getKeyCode() == KeyEvent.VK_ENTER //
    || e.getKeyCode() == KeyEvent.VK_DOWN //
    || e.getKeyCode() == KeyEvent.VK_KP_DOWN) {
   final ParameterTable parent = ParameterTable.this;
   if(!parent.isEditing()) {
    int leadRow = parent.getSelectionModel().getLeadSelectionIndex();
    int leadColumn = parent.getColumnModel().getSelectionModel().getLeadSelectionIndex();
    parent.editCellAt(leadRow, leadColumn);
    Component editorComponent = getEditorComponent();
    // This is a hack, to make the content assist open immediately.
    if(editorComponent instanceof DispatchingPanel) {
     KeyListener[] l = ((DispatchingPanel) editorComponent).component.getKeyListeners();
     for(KeyListener li : l) {
      li.keyPressed(e);
     }
    }
   }
  }
 }
}

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

private static void dispatchEvent(int eventCode, Key key, int keyCode, Component component) {
 int modifier = key.getModifier().getCode();
 KeyEvent event = new KeyEvent(component, eventCode, 0, modifier, keyCode, key.getChar());
 for (KeyListener listener : component.getKeyListeners()) {
  switch (eventCode) {
   case KEY_PRESSED:
    listener.keyPressed(event);
    break;
   case KEY_TYPED:
    listener.keyTyped(event);
    break;
   case KEY_RELEASED:
    listener.keyReleased(event);
    break;
  }
 }
 SwingUtilities.processKeyBindings(event);
}

相关文章