Example usage for javafx.scene.input KeyEvent KeyEvent

List of usage examples for javafx.scene.input KeyEvent KeyEvent

Introduction

In this page you can find the example usage for javafx.scene.input KeyEvent KeyEvent.

Prototype

public KeyEvent(@NamedArg("eventType") EventType<KeyEvent> eventType, @NamedArg("character") String character,
        @NamedArg("text") String text, @NamedArg("code") KeyCode code, @NamedArg("shiftDown") boolean shiftDown,
        @NamedArg("controlDown") boolean controlDown, @NamedArg("altDown") boolean altDown,
        @NamedArg("metaDown") boolean metaDown) 

Source Link

Document

Constructs a new KeyEvent event from the specified parameters, with a null source and target.

Usage

From source file:org.eclipse.jubula.rc.javafx.driver.RobotJavaFXImpl.java

/**
 * {@inheritDoc} <br>//from www .j a va 2s. c om
 * <b>* Currently delegates the key type to the Robot </b>
 */
public void type(final Object graphicsComponent, char c) throws RobotException {

    Validate.notNull(graphicsComponent, "The graphic component must not be null"); //$NON-NLS-1$

    final KeyEvent event = new KeyEvent(KeyEvent.KEY_TYPED, String.valueOf(c), StringUtils.EMPTY, null, false,
            false, false, false);

    InterceptorOptions options = new InterceptorOptions(new long[] { AWTEvent.KEY_EVENT_MASK });
    IRobotEventConfirmer confirmer = m_interceptor.intercept(options);

    m_queuer.invokeLater("Type character", new Runnable() { //$NON-NLS-1$
        @Override
        public void run() {
            final Scene scene;
            if (graphicsComponent instanceof Stage) {
                scene = ((Stage) graphicsComponent).getScene();
            } else {
                scene = ((Node) graphicsComponent).getScene();
            }

            Node focusOwner = scene.getFocusOwner();
            EventTarget eventTarget = focusOwner != null ? focusOwner : scene;

            Event.fireEvent(eventTarget, event);
        }
    });

    confirmer.waitToConfirm(graphicsComponent, new KeyJavaFXEventMatcher(KeyEvent.KEY_TYPED));

}