source dump of claude code
at main 36 lines 1.1 kB view raw
1export type ModifierKey = 'shift' | 'command' | 'control' | 'option' 2 3let prewarmed = false 4 5/** 6 * Pre-warm the native module by loading it in advance. 7 * Call this early to avoid delay on first use. 8 */ 9export function prewarmModifiers(): void { 10 if (prewarmed || process.platform !== 'darwin') { 11 return 12 } 13 prewarmed = true 14 // Load module in background 15 try { 16 // eslint-disable-next-line @typescript-eslint/no-require-imports 17 const { prewarm } = require('modifiers-napi') as { prewarm: () => void } 18 prewarm() 19 } catch { 20 // Ignore errors during prewarm 21 } 22} 23 24/** 25 * Check if a specific modifier key is currently pressed (synchronous). 26 */ 27export function isModifierPressed(modifier: ModifierKey): boolean { 28 if (process.platform !== 'darwin') { 29 return false 30 } 31 // Dynamic import to avoid loading native module at top level 32 const { isModifierPressed: nativeIsModifierPressed } = 33 // eslint-disable-next-line @typescript-eslint/no-require-imports 34 require('modifiers-napi') as { isModifierPressed: (m: string) => boolean } 35 return nativeIsModifierPressed(modifier) 36}