Variable KeyboardUtilsConst

KeyboardUtils: {
    getKeyCategory(key): KeyCategory;
    getKeyCombination(event): string;
    isAlphanumericKey(key): boolean;
    isArrowKey(event): boolean;
    isBackspaceKey(event): boolean;
    isDeleteKey(event): boolean;
    isEnterKey(event): boolean;
    isEscapeKey(event): boolean;
    isFunctionKey(key): boolean;
    isModifierKey(event): boolean;
    isNavigationKey(key): boolean;
    isNumericKey(key): boolean;
    isPunctuationKey(key): boolean;
    isSpaceKey(event): boolean;
    isTabKey(event): boolean;
    simulateClickOnEnter(event): void;
    stopEvent(event): void;
} = ...

Type declaration

  • getKeyCategory:function
    • Gets the category of a keyboard key

      Parameters

      • key: string

        The key to categorize

      Returns KeyCategory

      The category of the key

      Example

      const category = KeyboardUtils.getKeyCategory('a'); // 'alphanumeric'
      const arrowCategory = KeyboardUtils.getKeyCategory('ArrowUp'); // 'arrow'
      const modifierCategory = KeyboardUtils.getKeyCategory('Control'); // 'modifier'
  • getKeyCombination:function
    • Gets the key combination string for a keyboard event (e.g., "Ctrl+Shift+A")

      Parameters

      • event: KeyboardEvent

        The keyboard event to analyze

      Returns string

      A string representing the key combination

      Example

      // For a Ctrl+Shift+A event
      const combo = KeyboardUtils.getKeyCombination(event); // 'Ctrl+Shift+A'

      // For a single key press
      const singleKey = KeyboardUtils.getKeyCombination(event); // 'A'
  • isAlphanumericKey:function
    • Checks if the given keyboard event is for an alphanumeric key

      Parameters

      • key: string

        The key to check

      Returns boolean

      True if the key is alphanumeric

      Example

      const isAlpha = KeyboardUtils.isAlphanumericKey('a'); // true
      const isNum = KeyboardUtils.isAlphanumericKey('1'); // true
      const isSpecial = KeyboardUtils.isAlphanumericKey('@'); // false
  • isArrowKey:function
    • Checks if the given keyboard event is for an arrow key

      Parameters

      • event: KeyboardEvent

        The keyboard event to check

      Returns boolean

      True if the event is for an arrow key

      Example

      const isArrow = KeyboardUtils.isArrowKey(event); // true for ArrowUp, ArrowDown, etc.
      
  • isBackspaceKey:function
    • Checks if the given keyboard event is for the Backspace key

      Parameters

      • event: KeyboardEvent

        The keyboard event to check

      Returns boolean

      True if the event is for the Backspace key

      Example

      const isBackspace = KeyboardUtils.isBackspaceKey(event); // true for Backspace key
      
  • isDeleteKey:function
    • Checks if the given keyboard event is for the Delete key

      Parameters

      • event: KeyboardEvent

        The keyboard event to check

      Returns boolean

      True if the event is for the Delete key

      Example

      const isDelete = KeyboardUtils.isDeleteKey(event); // true for Delete key
      
  • isEnterKey:function
    • Checks if the given keyboard event is for the Enter key

      Parameters

      • event: KeyboardEvent

        The keyboard event to check

      Returns boolean

      True if the event is for the Enter key

      Example

      const isEnter = KeyboardUtils.isEnterKey(event); // true for Enter key
      
  • isEscapeKey:function
    • Checks if the given keyboard event is for the Escape key

      Parameters

      • event: KeyboardEvent

        The keyboard event to check

      Returns boolean

      True if the event is for the Escape key

      Example

      const isEscape = KeyboardUtils.isEscapeKey(event); // true for Escape key
      
  • isFunctionKey:function
    • Checks if the given keyboard event is for a function key (F1-F12)

      Parameters

      • key: string

        The key to check

      Returns boolean

      True if the key is a function key

      Example

      const isFunction = KeyboardUtils.isFunctionKey('F1'); // true
      const isNotFunction = KeyboardUtils.isFunctionKey('A'); // false
  • isModifierKey:function
    • Checks if the given keyboard event is for a modifier key

      Parameters

      • event: KeyboardEvent

        The keyboard event to check

      Returns boolean

      True if the event is for a modifier key

      Example

      const isModifier = KeyboardUtils.isModifierKey(event); // true for Control, Alt, Shift, Meta
      
  • isNavigationKey:function
    • Checks if the given keyboard event is for a navigation key

      Parameters

      • key: string

        The key to check

      Returns boolean

      True if the key is a navigation key

      Example

      const isNav = KeyboardUtils.isNavigationKey('Home'); // true
      const isNotNav = KeyboardUtils.isNavigationKey('A'); // false
  • isNumericKey:function
    • Checks if the given keyboard event is for a numeric key

      Parameters

      • key: string

        The key to check

      Returns boolean

      True if the key is numeric

      Example

      const isNum = KeyboardUtils.isNumericKey('1'); // true
      const isNotNum = KeyboardUtils.isNumericKey('A'); // false
  • isPunctuationKey:function
    • Checks if the given keyboard event is for a punctuation key

      Parameters

      • key: string

        The key to check

      Returns boolean

      True if the key is punctuation

      Example

      const isPunct = KeyboardUtils.isPunctuationKey('!'); // true
      const isNotPunct = KeyboardUtils.isPunctuationKey('A'); // false
  • isSpaceKey:function
    • Checks if the given keyboard event is for the Space key

      Parameters

      • event: KeyboardEvent

        The keyboard event to check

      Returns boolean

      True if the event is for the Space key

      Example

      const isSpace = KeyboardUtils.isSpaceKey(event); // true for Space key
      
  • isTabKey:function
    • Checks if the given keyboard event is for the Tab key

      Parameters

      • event: KeyboardEvent

        The keyboard event to check

      Returns boolean

      True if the event is for the Tab key

      Example

      const isTab = KeyboardUtils.isTabKey(event); // true for Tab key
      
  • simulateClickOnEnter:function
    • Simulates a click event on the target element when Enter key is pressed

      Parameters

      • event: KeyboardEvent

        The keyboard event to handle

      Returns void

      Example

      // Add to a button's keydown event
      button.addEventListener('keydown', (event) => {
      KeyboardUtils.simulateClickOnEnter(event);
      });
  • stopEvent:function
    • Stops the default action and prevents event propagation

      Parameters

      • event: KeyboardEvent

        The keyboard event to handle

      Returns void

      Example

      // Prevent default behavior and stop propagation
      element.addEventListener('keydown', (event) => {
      KeyboardUtils.stopEvent(event);
      });