Keys

The Keys item extension allows prototypes to react to physical key presses. The Keys element only reacts to key events when the item it is extending (or one of its children) has input focus.

Rectangle as root {
    color: #white

    with Keys as keys {
        on pressed {
            if key.isUp {
                System.log("Up arrow pressed")
            } else if key.isDown {
                System.log("Down arrow pressed")
            } else {
                System.log("Other key pressed")
                ignoreKey()
            }
        }
    }
}

event pressed(Keys.Event e)

event released(Keys.Event e)

The pressed and released events fire when keys on the keyboard are pressed or released.

Rectangle as root {
    color: #white

    with Keys {
        on pressed {
            System.log("pressed")
        }
        on released {
            System.log("released")
        }
    }
}

property Keys.Key keyread only

Keys.Key.Up

The up arrow key.

Keys.Key.Down

The down arrow key.

Keys.Key.Left

The left arrow key.

Keys.Key.Right

The right arrow key.

Keys.Key.Back

The Android back key.

Keys.Key.Return

The return key.

Keys.Key.Escape

The escape key.

Keys.Key.Other

Another key.

property Int keyCoderead only

When a key is pressed this property shows the unique keyCode.

property Bool isAutoRepeatread only

true if the key press is a repeat caused by the user holding the key down, false if the key press is new.

property String textread only

When a key is pressed this property shows the text based charecter

property Keys.Modifier modifiersread only

static function Keys.modifiers() → Keys.Modifier

Keys.Modifier.Shift

Keys.Modifier.Control

Keys.Modifier.Alt

Keys.Modifier.Meta

function ignoreKey()

Ignore the currently pressed key.