event.descriptor

Type String
Event key
Revision Release 2022.3683
Keywords key, descriptor

Overview

Provides a human-readable string (assigned by Corona) which can be used to uniquely identify one key belonging to a device. This descriptor string is intended to be used by applications that set up key and axis bindings with a particular device, such as the first joystick connected to the system.

This descriptor string key is generated based on the device's descriptor and the name of the key that was pressed or released. For example, the first 2 buttons belonging to one joystick might be named Joystick 1: buttonA and Joystick 1: buttonB.

Gotchas

The descriptor name will not contain a device name if the key event was generated by software, such as Android's bottom navigation bar shown onscreen. This is typical of the Back key event — in this case, only the key name is provided by this descriptor. For example, if you press the Back key on an Android device's touchscreen, the descriptor name will be back.

Example

-- Called when a key event has been received
local function onKeyEvent( event )
    -- Print the key's unique descriptor
    print( event.descriptor )

    -- Return false to indicate that this app is NOT overriding the received key;
    -- This lets the operating system execute its default handling of this key
    return false
end

-- Add the key event listener
Runtime:addEventListener( "key", onKeyEvent )