@@ -25,7 +25,11 @@ function wasModifierPressed(event: KeyboardEvent) {
2525}
2626
2727function isKeyMatch ( pressedKey : string , keyToMatch : string , pressedKeys : Set < string > , isKeyUp : boolean ) {
28- const keyCombination = keyToMatch . split ( '+' ) . map ( ( k ) => k . trim ( ) . toLowerCase ( ) )
28+ const keyCombination = keyToMatch
29+ . replace ( '+' , '\n' )
30+ . replace ( '\n\n' , '\n+' )
31+ . split ( '\n' )
32+ . map ( ( k ) => k . trim ( ) . toLowerCase ( ) )
2933
3034 if ( keyCombination . length === 1 ) {
3135 return pressedKey . toLowerCase ( ) === keyToMatch . toLowerCase ( )
@@ -50,13 +54,16 @@ function createKeyPredicate(keyFilter: string | string[], pressedKeys: Set<strin
5054
5155 const keyOrCode = useKeyOrCode ( event . code , keyFilter )
5256
57+ const isKeyUp = event . type === 'keyup'
58+ const pressedKey = event [ keyOrCode ]
59+
5360 // if the keyFilter is an array of multiple keys, we need to check each possible key combination
5461 if ( Array . isArray ( keyFilter ) ) {
55- return keyFilter . some ( ( key ) => isKeyMatch ( event [ keyOrCode ] , key , pressedKeys , event . type === 'keyup' ) )
62+ return keyFilter . some ( ( key ) => isKeyMatch ( pressedKey , key , pressedKeys , isKeyUp ) )
5663 }
5764
5865 // if the keyFilter is a string, we need to check if the key matches the string
59- return isKeyMatch ( event [ keyOrCode ] , keyFilter , pressedKeys , event . type === 'keyup' )
66+ return isKeyMatch ( pressedKey , keyFilter , pressedKeys , isKeyUp )
6067 }
6168}
6269
@@ -126,7 +133,9 @@ export function useKeyPress(keyFilter: MaybeRefOrGetter<KeyFilter | boolean | nu
126133 )
127134
128135 onKeyStroke (
129- ( ...args ) => currentFilter ( ...args ) ,
136+ ( ...args ) => {
137+ return currentFilter ( ...args )
138+ } ,
130139 ( e ) => {
131140 if ( isPressed . value ) {
132141 const preventAction = ( ! modifierPressed || ( modifierPressed && ! actInsideInputWithModifier . value ) ) && isInputDOMNode ( e )
0 commit comments