key

Type Event
Dispatch chain Runtime
Revision Current Public Release (2014.2393)
Keywords key

Overview

Key events occur when a keyboard key or gamepad/joystick button has been pressed down or released.

In your key event listener, you can return true to indicate that your app will be handling the received key and overriding the operating system's default behavior. For example, on Android, returning true for the "back" key will prevent the operating system from backing out of your app.

Returning false in the key event listener indicates that your app is not overriding the key and allows the operating system to execute its default behavior.

Android

Android raises key events for all keyboard keys, navigation buttons, volume buttons, and gamepad/joystick buttons. Android does not raise key events for the Home navigation button, Task Manager button, or Power button.

iOS

Does not support key events.

Windows

The Corona Simulator for Windows only supports key events when simulating an Android device. Currently, Windows only supports keyboard keys and not gamepad/joystick buttons.

Gotchas

Key events will not be received if a native object such as a TextField, TextBox, or WebView handles them. This can only happen if these native objects have the focus and if they choose to override that key. For example, a TextField and TextBox typically handles all keyboard keys, preventing the application from receiving those key events, but will not handle a "back" key event.

Properties

event.phase