
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
@keekuun/keymaster-core
Advanced tools
keymaster core module, providing shared type definitions, parsers, and utility functions for React and Vue versions.
Note: Usually you don't need to install this package directly. It's automatically installed as a dependency of
@keekuun/keymaster-reactand@keekuun/keymaster-vue. If you need to use core functionality in other projects, you can install it separately.
@keekuun/keymaster-core is the underlying core module of @keekuun/keymaster-react and @keekuun/keymaster-vue, containing:
"ctrl+s") into structured objectsisValidShortcut() and formatShortcut() for shortcut validation and formattingWhen you install @keekuun/keymaster-react or @keekuun/keymaster-vue, keymaster-core will be automatically installed as a dependency:
npm install @keekuun/keymaster-react
# keymaster-core will be automatically installed
If you need to use core functionality in other projects, you can install it separately:
npm install @keekuun/keymaster-core
# or
pnpm add @keekuun/keymaster-core
KeymasterHandlerKeyboard event handler function type:
type KeymasterHandler = (event: KeyboardEvent) => void;
KeymasterBindingOptionsBaseBase interface for shortcut binding options:
interface KeymasterBindingOptionsBase {
preventDefault?: boolean; // Whether to prevent default behavior
stopPropagation?: boolean; // Whether to stop event propagation
scopedElement?: HTMLElement | null; // Scoped element
editorMode?: boolean; // Editor mode
electronMode?: boolean; // Electron mode
}
ParsedShortcutParsed shortcut structure:
interface ParsedShortcut {
key: string; // Main key (e.g., "s", "enter")
ctrl: boolean; // Whether Ctrl is pressed
alt: boolean; // Whether Alt is pressed
shift: boolean; // Whether Shift is pressed
meta: boolean; // Whether Meta/Cmd is pressed
}
ElectronWindowElectron environment Window type extension:
interface ElectronWindow extends Window {
process?: {
type?: string;
versions?: {
electron?: string;
node?: string;
chrome?: string;
};
};
}
parseShortcut(shortcut: string): ParsedShortcutParse a shortcut string into a structured object:
import { parseShortcut } from '@keekuun/keymaster-core';
const parsed = parseShortcut('ctrl+shift+s');
// { key: "s", ctrl: true, shift: true, alt: false, meta: false }
isMatchingShortcut(event: KeyboardEvent, parsed: ParsedShortcut): booleanDetermine if a keyboard event matches the parsed shortcut:
import { isMatchingShortcut, parseShortcut } from '@keekuun/keymaster-core';
const parsed = parseShortcut('ctrl+s');
const isMatch = isMatchingShortcut(keyboardEvent, parsed);
isEventInScope(event: KeyboardEvent, scopedElement: HTMLElement): booleanCheck if an event occurred within a scoped element:
import { isEventInScope } from '@keekuun/keymaster-core';
const isInScope = isEventInScope(keyboardEvent, editorElement);
isElectronEnvironment(): booleanDetect if currently running in an Electron environment:
import { isElectronEnvironment } from '@keekuun/keymaster-core';
if (isElectronEnvironment()) {
// Handle Electron-specific logic
}
getElectronProcessInfo(): ElectronWindow["process"] | nullGet Electron process information (if available):
import { getElectronProcessInfo } from '@keekuun/keymaster-core';
const processInfo = getElectronProcessInfo();
if (processInfo) {
console.log(processInfo.type); // "renderer" or "main"
}
The KeyBindingManager class allows you to manage a group of related shortcut bindings. It's framework-agnostic and can be used independently in any JavaScript/TypeScript project.
Note: To use KeyBindingManager, you need to provide a registration function that matches your framework or custom implementation.
import { KeyBindingManager } from '@keekuun/keymaster-core';
// Create manager instance - no registration function needed!
const manager = new KeyBindingManager();
// Chain register multiple shortcuts
manager
.register('ctrl+s', () => console.log('Save'))
.register('ctrl+z', () => console.log('Undo'))
.register('ctrl+shift+z', () => console.log('Redo'));
// Clean up all bindings
manager.dispose();
import { KeyBindingManager } from '@keekuun/keymaster-core';
const manager = new KeyBindingManager();
// Register with options (scoped element, prevent default, etc.)
const editorElement = document.getElementById('editor');
manager
.register('ctrl+s', () => console.log('Save'), {
scopedElement: editorElement,
preventDefault: true,
})
.register('ctrl+k', () => console.log('Search'), {
scopedElement: editorElement,
preventDefault: true,
stopPropagation: true,
});
If you want to use a custom registration function (e.g., from React/Vue packages), you can pass it as a parameter:
import { KeyBindingManager } from '@keekuun/keymaster-core';
import { registerKeyBinding } from '@keekuun/keymaster-react';
// Use React's registration function for better framework integration
const manager = new KeyBindingManager(registerKeyBinding);
manager.register('ctrl+s', () => console.log('Save')).register('ctrl+z', () => console.log('Undo'));
When using with React or Vue, you can use the framework-specific createKeyBindingManager:
// React
import { createKeyBindingManager } from '@keekuun/keymaster-react';
const manager = createKeyBindingManager();
// Vue
import { createKeyBindingManager } from '@keekuun/keymaster-vue';
const manager = createKeyBindingManager();
import { isValidShortcut, formatShortcut } from '@keekuun/keymaster-core';
// Validate shortcut format
isValidShortcut('ctrl+s'); // true
isValidShortcut('invalid'); // false
// Format shortcut string
formatShortcut('Ctrl+S'); // 'ctrl+s'
formatShortcut('ctrl + shift + z'); // 'ctrl+shift+z'
import {
MODIFIER_CTRL,
MODIFIER_ALT,
MODIFIER_SHIFT,
MODIFIER_META,
MODIFIER_CMD,
PLUS_SEPARATOR,
MODIFIERS,
} from '@keekuun/keymaster-core';
If you need to implement custom shortcut handling logic, you can directly use the core module:
import { parseShortcut, isMatchingShortcut, type KeymasterHandler } from '@keekuun/keymaster-core';
function createCustomKeyHandler(shortcut: string, handler: KeymasterHandler) {
const parsed = parseShortcut(shortcut);
return (event: KeyboardEvent) => {
if (isMatchingShortcut(event, parsed)) {
handler(event);
}
};
}
import { parseShortcut } from '@keekuun/keymaster-core';
function validateShortcut(shortcut: string): boolean {
try {
parseShortcut(shortcut);
return true;
} catch {
return false;
}
}
The core package supports multiple build formats for different use cases:
dist/index.js): For modern bundlers and ES module environmentsdist/index.cjs): For Node.js and CommonJS environmentsdist/index.umd.js): For browser <script> tags and CDN usage (core package only)Note: UMD format is only available for
@keekuun/keymaster-core. React and Vue packages (@keekuun/keymaster-reactand@keekuun/keymaster-vue) do not provide UMD builds as they require framework environments and are typically used with modern bundlers.
You can use the UMD build directly in the browser for the core package:
<!-- Via unpkg CDN -->
<script src="https://unpkg.com/@keekuun/keymaster-core/dist/index.umd.js"></script>
<!-- Or via jsdelivr CDN -->
<script src="https://cdn.jsdelivr.net/npm/@keekuun/keymaster-core/dist/index.umd.js"></script>
<script>
// Access via global variable KeymasterCore
const { KeyBindingManager, parseShortcut, isValidShortcut, formatShortcut } = KeymasterCore;
// Example: Use KeyBindingManager with your own registration function
function myRegisterKeyBinding(shortcut, handler, options) {
const listener = (event) => {
// Your custom matching logic
handler(event);
};
window.addEventListener('keydown', listener);
return () => window.removeEventListener('keydown', listener);
}
const manager = new KeyBindingManager(myRegisterKeyBinding);
manager
.register('ctrl+s', () => console.log('Save'))
.register('ctrl+z', () => console.log('Undo'));
</script>
Use Cases for UMD:
Limitations:
@keekuun/keymaster-react@keekuun/keymaster-vueFAQs
keymaster 核心模块(React 和 Vue 共享的类型、解析器和工具函数)
The npm package @keekuun/keymaster-core receives a total of 2 weekly downloads. As such, @keekuun/keymaster-core popularity was classified as not popular.
We found that @keekuun/keymaster-core demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.