One of the recent requirements is to select multiple elements when you hold CTRL,

The question is: how to determine whether CTRL is pressed? After looking up some data, it is found that some attributes of E can be determined

E. clkey Is set when CTRL is pressedtrueE. shifftKey shift when holding downtrueE. metaKey Win when you hold down the keytrueOn MAC, the WIN key is commandCopy the code

Some attributes of E can be judged in the corresponding events:

        document.addEventListener('click'.(e) = >{
            console.log('e.ctrlKey',e.ctrlKey) // Determine whether CTRL is pressed
            console.log('e.shiftKey',e.shiftKey) // Determine if shift is down
            console.log('e.metaKey',e.metaKey) // Check whether the win key is pressed.
        })

Copy the code