# all files / diagram-js/lib/features/keyboard/ KeyboardUtil.js

85.71% Statements 6/7
90% Branches 9/10
100% Functions 4/4
85.71% Lines 6/7

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42

    24×

    204×

    204×

    102×

    102×

    4×
     import { isArray } from 'min-dash';

    /**
     * Returns true if event was triggered with any modifier
     * @param {KeyboardEvent} event
     */
    export function hasModifier(event) {
      return (event.ctrlKey || event.metaKey || event.shiftKey || event.altKey);
    }

    /**
     * @param {KeyboardEvent} event
     */
    export function isCmd(event) {

      // ensure we don't react to AltGr
      // (mapped to CTRL + ALT)
      Iif (event.altKey) {
        return false;
      }

      return event.ctrlKey || event.metaKey;
    }

    /**
     * Checks if key pressed is one of provided keys.
     *
     * @param {String|String[]} keys
     * @param {KeyboardEvent} event
     */
    export function isKey(keys, event) {
      keys = isArray(keys) ? keys : [ keys ];

      return keys.indexOf(event.key) > -1;
    }

    /**
     * @param {KeyboardEvent} event
     */
    export function isShift(event) {
      return event.shiftKey;
    }