Key

Static Properties

  • Key.modifiers

    The current state of the keyboard modifiers.

    • Type:

    • Object

    • Options:

    • modifiers.shift: Booleantrue if the shift key is pressed, false otherwise.

    • modifiers.control: Booleantrue if the control key is pressed, false otherwise.

    • modifiers.alt: Booleantrue if the alt/option key is pressed, false otherwise.

    • modifiers.meta: Booleantrue if the meta/windows/command key is pressed, false otherwise.

    • modifiers.capsLock: Booleantrue if the caps-lock key is active, false otherwise.

    • modifiers.space: Booleantrue if the space key is pressed, false otherwise.

    • modifiers.option: Booleantrue if the alt/option key is pressed, false otherwise. This is the same as modifiers.alt

    • modifiers.command: Booleantrue if the meta key is pressed on Mac, or the control key is pressed on Windows and Linux, false otherwise.

Static Methods

  • Key.isDown(key)

    Checks whether the specified key is pressed.

    • Parameters:

    • key: String — any character or special key descriptor: ‘enter’, ‘space’, ‘shift’, ‘control’, ‘alt’, ‘meta’, ‘caps-lock’, ‘left’, ‘up’, ‘right’, ‘down’, ‘escape’, ‘delete’, …

    • Returns:

    • Booleantrue if the key is pressed, false otherwise

    Example:Whenever the user clicks, create a circle shaped path. If the 'a' key is pressed, fill it with red, otherwise fill it with blue:

    function onMouseDown(event) {
        var path = new Path.Circle(event.point, 10);
        if (Key.isDown('a')) {
            path.fillColor = 'red';
        } else {
            path.fillColor = 'blue';
        }
    }