Google Web Toolkit (Beta)
Search this site:

# Interface KeyboardListener

public interface KeyboardListener
extends EventListener
// Implemented by `KeyboardListenerAdapter`, `DelegatingKeyboardListenerCollection`
Event listener interface for keyboard events.

## Fields

KEY_ALT |
KEY_BACKSPACE |
KEY_CTRL |
KEY_DELETE |
KEY_DOWN |
KEY_END |
KEY_ENTER |
KEY_ESCAPE |
KEY_HOME |
KEY_LEFT |
KEY_PAGEDOWN |
KEY_PAGEUP |
KEY_RIGHT |
KEY_SHIFT |
KEY_TAB |
KEY_UP |
MODIFIER_ALT |
MODIFIER_CTRL |
MODIFIER_META |
MODIFIER_SHIFT |

## Methods

onKeyDown(Widget, char, int) | Fired when the user depresses a physical key.
onKeyPress(Widget, char, int) | Fired when a keyboard action generates a character.
onKeyUp(Widget, char, int) | Fired when the user releases a physical key.

## Field Detail

### KEY_ALT

public static final int KEY_ALT

### KEY_BACKSPACE

public static final int KEY_BACKSPACE

### KEY_CTRL

public static final int KEY_CTRL

### KEY_DELETE

public static final int KEY_DELETE

### KEY_DOWN

public static final int KEY_DOWN

### KEY_END

public static final int KEY_END

### KEY_ENTER

public static final int KEY_ENTER

### KEY_ESCAPE

public static final int KEY_ESCAPE

### KEY_HOME

public static final int KEY_HOME

### KEY_LEFT

public static final int KEY_LEFT

### KEY_PAGEDOWN

public static final int KEY_PAGEDOWN

### KEY_PAGEUP

public static final int KEY_PAGEUP

### KEY_RIGHT

public static final int KEY_RIGHT

### KEY_SHIFT

public static final int KEY_SHIFT

### KEY_TAB

public static final int KEY_TAB

### KEY_UP

public static final int KEY_UP

### MODIFIER_ALT

public static final int MODIFIER_ALT

### MODIFIER_CTRL

public static final int MODIFIER_CTRL

### MODIFIER_META

public static final int MODIFIER_META

### MODIFIER_SHIFT

public static final int MODIFIER_SHIFT

## Method Detail

### onKeyDown

public void onKeyDown(Widget sender, char keyCode, int modifiers)
Fired when the user depresses a physical key.

#### Parameters

sender
  the widget that was focused when the event occurred.
keyCode
  the physical key that was depressed. Constants for this value are defined in this interface with the KEY prefix.
modifiers
  the modifier keys pressed at when the event occurred. This value is a combination of the bits defined by KeyboardListener.MODIFIER_SHIFT, KeyboardListener.MODIFIER_CTRL, and KeyboardListener.MODIFIER_ALT.

### onKeyPress

public void onKeyPress(Widget sender, char keyCode, int modifiers)
Fired when a keyboard action generates a character. This occurs after onKeyDown and onKeyUp are fired for the physical key that was pressed.

It should be noted that many browsers do not generate keypress events for non-printing keyCode values, such as KeyboardListener.KEY_ENTER or arrow keys. These keyCodes can be reliably captured either with KeyboardListener.onKeyDown(Widget, char, int) or KeyboardListener.onKeyUp(Widget, char, int).

#### Parameters

sender
  the widget that was focused when the event occurred.
keyCode
  the Unicode character that was generated by the keyboard action.
modifiers
  the modifier keys pressed at when the event occurred. This value is a combination of the bits defined by KeyboardListener.MODIFIER_SHIFT, KeyboardListener.MODIFIER_CTRL, and KeyboardListener.MODIFIER_ALT.

### onKeyUp

public void onKeyUp(Widget sender, char keyCode, int modifiers)
Fired when the user releases a physical key.

#### Parameters

sender
  the widget that was focused when the event occurred.
keyCode
  the physical key that was released. Constants for this value are defined in this interface with the KEY prefix.
modifiers
  the modifier keys pressed at when the event occurred. This value is a combination of the bits defined by KeyboardListener.MODIFIER_SHIFT, KeyboardListener.MODIFIER_CTRL, and KeyboardListener.MODIFIER_ALT.