modifiers.ts
utils/modifiers.ts
No strong subsystem tag
37
Lines
1112
Bytes
3
Exports
0
Imports
10
Keywords
What this is
This page documents one file from the repository and includes its full source so you can read it without leaving the docs site.
Beginner explanation
This file is one piece of the larger system. Its name, directory, imports, and exports show where it fits. Start by reading the exports and related files first.
How it is used
Start from the exports list and related files. Those are the easiest clues for where this file fits into the system.
Expert explanation
Architecturally, this file intersects with general runtime concerns. It contains 37 lines, 0 detected imports, and 3 detected exports.
Important relationships
Detected exports
ModifierKeyprewarmModifiersisModifierPressed
Keywords
prewarmprewarmedmodifierismodifierpressedmodifierkeynativeloadingavoidvoidprocess
Detected imports
- No import paths detected.
Source notes
This page embeds the full file contents. Small or leaf files are still indexed honestly instead of being over-explained.
Full source
export type ModifierKey = 'shift' | 'command' | 'control' | 'option'
let prewarmed = false
/**
* Pre-warm the native module by loading it in advance.
* Call this early to avoid delay on first use.
*/
export function prewarmModifiers(): void {
if (prewarmed || process.platform !== 'darwin') {
return
}
prewarmed = true
// Load module in background
try {
// eslint-disable-next-line @typescript-eslint/no-require-imports
const { prewarm } = require('modifiers-napi') as { prewarm: () => void }
prewarm()
} catch {
// Ignore errors during prewarm
}
}
/**
* Check if a specific modifier key is currently pressed (synchronous).
*/
export function isModifierPressed(modifier: ModifierKey): boolean {
if (process.platform !== 'darwin') {
return false
}
// Dynamic import to avoid loading native module at top level
const { isModifierPressed: nativeIsModifierPressed } =
// eslint-disable-next-line @typescript-eslint/no-require-imports
require('modifiers-napi') as { isModifierPressed: (m: string) => boolean }
return nativeIsModifierPressed(modifier)
}