@@ -76,11 +76,19 @@ function setupHook(): HookHandle {
7676 } ;
7777}
7878
79- function keydown ( init : { code : string ; key : string ; shiftKey ?: boolean } ) : KeyboardEvent {
79+ function keydown ( init : {
80+ code : string ;
81+ key : string ;
82+ shiftKey ?: boolean ;
83+ metaKey ?: boolean ;
84+ altKey ?: boolean ;
85+ } ) : KeyboardEvent {
8086 return new KeyboardEvent ( "keydown" , {
8187 code : init . code ,
8288 key : init . key ,
8389 shiftKey : init . shiftKey ?? false ,
90+ metaKey : init . metaKey ?? false ,
91+ altKey : init . altKey ?? false ,
8492 cancelable : true ,
8593 } ) ;
8694}
@@ -447,3 +455,31 @@ describe("usePlaybackKeyboard: space, arrows, loop and clear keys are combos", (
447455 expect ( usePlayerStore . getState ( ) . inPoint ) . toBeNull ( ) ;
448456 } ) ;
449457} ) ;
458+
459+ describe ( "usePlaybackKeyboard: modifier combos and named keys" , ( ) => {
460+ const send = ( dispatch : HookHandle [ "dispatch" ] , init : Parameters < typeof keydown > [ 0 ] ) =>
461+ act ( ( ) => {
462+ dispatch ( keydown ( init ) ) ;
463+ } ) ;
464+
465+ it ( "a playback action remapped to a Cmd or Alt combo answers, and the plain key does not" , ( ) => {
466+ setStudioKeys ( { playPause : "mod+p" , mute : "alt+m" } ) ;
467+ const { dispatch, spies } = setupHook ( ) ;
468+ usePlayerStore . setState ( { isPlaying : false , audioMuted : false } ) ;
469+ send ( dispatch , { code : "KeyP" , key : "p" , metaKey : true } ) ;
470+ expect ( spies . play ) . toHaveBeenCalledTimes ( 1 ) ;
471+ send ( dispatch , { code : "KeyM" , key : "µ" , altKey : true } ) ;
472+ expect ( usePlayerStore . getState ( ) . audioMuted ) . toBe ( true ) ;
473+ send ( dispatch , { code : "KeyP" , key : "p" } ) ;
474+ expect ( spies . play ) . toHaveBeenCalledTimes ( 1 ) ;
475+ } ) ;
476+
477+ it ( "holding a stop key that is a named key still frame-steps instead of shuttling" , ( ) => {
478+ setStudioKeys ( { pause : "Home" } ) ;
479+ const { dispatch, spies } = setupHook ( ) ;
480+ send ( dispatch , { code : "Home" , key : "Home" } ) ;
481+ send ( dispatch , { code : "KeyJ" , key : "j" } ) ;
482+ expect ( spies . seek ) . toHaveBeenCalledTimes ( 1 ) ;
483+ expect ( spies . playBackward ) . not . toHaveBeenCalled ( ) ;
484+ } ) ;
485+ } ) ;
0 commit comments