Const
The key to categorize
The category of the key
const category = KeyboardUtils.getKeyCategory('a'); // 'alphanumeric'
const arrowCategory = KeyboardUtils.getKeyCategory('ArrowUp'); // 'arrow'
const modifierCategory = KeyboardUtils.getKeyCategory('Control'); // 'modifier'
Gets the key combination string for a keyboard event (e.g., "Ctrl+Shift+A")
The keyboard event to analyze
A string representing the key combination
// 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'
Checks if the given keyboard event is for an alphanumeric key
The key to check
True if the key is alphanumeric
const isAlpha = KeyboardUtils.isAlphanumericKey('a'); // true
const isNum = KeyboardUtils.isAlphanumericKey('1'); // true
const isSpecial = KeyboardUtils.isAlphanumericKey('@'); // false
Checks if the given keyboard event is for a function key (F1-F12)
The key to check
True if the key is a function key
const isFunction = KeyboardUtils.isFunctionKey('F1'); // true
const isNotFunction = KeyboardUtils.isFunctionKey('A'); // false
Checks if the given keyboard event is for a navigation key
The key to check
True if the key is a navigation key
const isNav = KeyboardUtils.isNavigationKey('Home'); // true
const isNotNav = KeyboardUtils.isNavigationKey('A'); // false
Checks if the given keyboard event is for a punctuation key
The key to check
True if the key is punctuation
const isPunct = KeyboardUtils.isPunctuationKey('!'); // true
const isNotPunct = KeyboardUtils.isPunctuationKey('A'); // false
Simulates a click event on the target element when Enter key is pressed
The keyboard event to handle
// Add to a button's keydown event
button.addEventListener('keydown', (event) => {
KeyboardUtils.simulateClickOnEnter(event);
});
Gets the category of a keyboard key