List of usage examples for java.awt.event KeyListener keyPressed
public void keyPressed(KeyEvent e);
From source file:KeyUtils.java
public static void pressKey(Component component) { if (component.getKeyListeners().length > 0) { KeyEvent event = new KeyEvent(component, KeyEvent.KEY_PRESSED, 0, 1, 32, (char) 32); for (int i = 0; i < component.getKeyListeners().length; i++) { KeyListener keyListener = component.getKeyListeners()[i]; keyListener.keyPressed(event); }// ww w . j av a 2 s .c o m } if (JComponent.class.isInstance(component)) { KeyStroke keyStroke = KeyStroke.getKeyStroke(32, 1); final ActionListener actionForKeyStroke = ((JComponent) component).getActionForKeyStroke(keyStroke); if (actionForKeyStroke != null) { actionForKeyStroke.actionPerformed(new ActionEvent(component, KeyEvent.KEY_PRESSED, "")); } } }