Check out example codes for "components key events gutenberg". It will help you in understanding the concepts better.

Code Example 1

import { KeyboardShortcuts } from '@wordpress/components';
import { withState } from '@wordpress/compose';
 
const MyKeyboardShortcuts = withState( {
    isAllSelected: false,
} )( ( { isAllSelected, setState } ) => { 
    const selectAll = () => {
        setState( { isAllSelected: true } )
    };
 
    return (
        <div>
            <KeyboardShortcuts shortcuts={ {
                'mod+a': selectAll,
            } } />
            [cmd/ctrl + A] Combination pressed? { isAllSelected ? 'Yes' : 'No' }
        </div>
    ) 
} )

Learn ReactJs, React Native from akashmittal.com