1 /*******************************************************************************
2 * Copyright (c) 2000, 2016 IBM Corporation and others.
4 * This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License 2.0
6 * which accompanies this distribution, and is available at
7 * https://www.eclipse.org/legal/epl-2.0/
9 * SPDX-License-Identifier: EPL-2.0
12 * IBM Corporation - initial API and implementation
13 * Lars Vogel <Lars.Vogel@vogella.com> - Bug 507185
14 *******************************************************************************/
15 package org.eclipse.swt.events;
18 import java.util.function.*;
20 import org.eclipse.swt.internal.*;
23 * Classes which implement this interface provide methods
24 * that deal with the events that are generated as keys
25 * are pressed on the system keyboard.
27 * After creating an instance of a class that implements
28 * this interface it can be added to a control using the
29 * <code>addKeyListener</code> method and removed using
30 * the <code>removeKeyListener</code> method. When a
31 * key is pressed or released, the appropriate method will
38 public interface KeyListener extends SWTEventListener {
41 * Sent when a key is pressed on the system keyboard.
43 * @param e an event containing information about the key press
45 void keyPressed(KeyEvent e);
48 * Sent when a key is released on the system keyboard.
50 * @param e an event containing information about the key release
52 void keyReleased(KeyEvent e);
55 * Static helper method to create a <code>KeyListener</code> for the
56 * {@link #keyPressed(KeyEvent e)}) method with a lambda expression.
58 * @param c the consumer of the event
62 static KeyListener keyPressedAdapter(Consumer<KeyEvent> c) {
63 return new KeyAdapter() {
65 public void keyPressed(KeyEvent e) {
72 * Static helper method to create a <code>KeyListener</code> for the
73 * {@link #keyReleased(KeyEvent e)}) method with a lambda expression.
75 * @param c the consumer of the event
79 static KeyListener keyReleasedAdapter(Consumer<KeyEvent> c) {
80 return new KeyAdapter() {
82 public void keyReleased(KeyEvent e) {