Spec-Zone .ru
спецификации, руководства, описания, API

JavaFX: Bringing Rich Experiences To All the Screens Of Your Life

expand all

Profile: desktop, common

Overview

An event which indicates that a keystroke occurred in a Node.

This event is generated when a key is pressed, released, or typed. Depending on the type of the event it is passed to Node#onKeyPressed, Node#onKeyTyped or Node#onKeyReleased function.

"Key typed" events are higher-level and generally do not depend on the platform or keyboard layout. They are generated when a Unicode character is entered, and are the preferred way to find out about character input. In the simplest case, a key typed event is produced by a single key press (e.g., 'a'). Often, however, characters are produced by series of key presses (e.g., SHIFT + 'a'), and the mapping from key pressed events to key typed events may be many-to-one or many-to-many. Key releases are not usually necessary to generate a key typed event, but there are some cases where the key typed event is not generated until a key is released (e.g., entering ASCII sequences via the Alt-Numpad method in Windows). No key typed events are generated for keys that don't generate Unicode characters (e.g., action keys, modifier keys, etc.).

The char variable always contains a valid Unicode character or CHAR_UNDEFINED. Character input is reported by key typed events; key pressed and key released events are not necessarily associated with character input. Therefore, the char variable is guaranteed to be meaningful only for key typed events.

For key pressed and key released events, the code variable contains the event's key code. For key typed events, the code variable always contains KeyCode.VK_UNDEFINED.

"Key pressed" and "key released" events are lower-level and depend on the platform and keyboard layout. They are generated whenever a key is pressed or released, and are the only way to find out about keys that don't generate character input (e.g., action keys, modifier keys, etc.). The key being pressed or released is indicated by the code variable, which contains a virtual key code.

Profile: common

Script Variable Summary

accessnametypeCan ReadCan InitCan WriteDefault Valuedescription
publicCHAR_UNDEFINEDString

KEY_PRESSED and KEY_RELEASED events which do not map to a valid Unicode character use this for the keyChar value.

Variable Summary

accessnametypeCan ReadCan InitCan WriteDefault Valuedescription
public-readaltDownBoolean

Returns whether or not the Alt modifier is down on this event.

public-readcharString

The unicode character associated with the key typed event.

The unicode character associated with the key typed event. For example, char will have the value "A" for a key typed event generated by pressing SHIFT + 'a'. For key pressed and key released events, char is always CHAR_UNDEFINED.

Profile: common

 
public-readcodeKeyCode

The integer key code associated with the key in this key pressed or key released event.

The integer key code associated with the key in this key pressed or key released event. For key typed events, code is always KeyCode.UNDEFINED.

Profile: common

 
public-readcontrolDownBoolean

Returns whether or not the Control modifier is down on this event.

public-readmetaDownBoolean

Returns whether or not the Meta modifier is down on this event.

public-initnodeNode

The Node on which this event has occurred.

public-readshiftDownBoolean

Returns whether or not the Shift modifier is down on this event.

public-readtextString

A String describing the key code, such as "HOME", "F1" or "A", for key pressed and key released events.

A String describing the key code, such as "HOME", "F1" or "A", for key pressed and key released events. For key typed events, text is always the empty string.

Profile: common

 

Inherited Variables

Script Function Summary

Function Summary

public toString() : java.lang.String
Returns
String
 

Inherited Functions