Detect modifier keys on button click eveent

This can be achieved with the following code.

const handleClick = (event) => {
  if(event.altKey) {
    console.log('altKey') ;
  }

  if(event.ctrlKey) {
    console.log('ctrlKey') ;
  }
} ;

However, there was some caveats at the time I tried it. Not sure now.

  • You need to use sp-button instead of button element.
  • ctrlKey acquisition is unstable on Windows.