JSFiddle - React, Tailwind, and code Playground

by jshwek

HTML

<h4>Try pressing the <b>CTRL</b>+<b>C</b> and checking the console</h4>
<h4>Try pressing the <b>CTRL</b>+<b>V</b> and checking the console</h4>

JavaScript

let ctrlActive = false;
      let cActive = false;
      let vActive = false

      document.body.addEventListener('keyup', event => {
        if (event.key === 'Control') ctrlActive = false;
        if (event.code === 'KeyC') cActive = false;
        if (event.code === 'KeyV') vActive = false;
      })

      document.body.addEventListener('keydown', event => {
        if (event.key === 'Control') ctrlActive = true;
        if (ctrlActive === true && event.code === 'KeyC') {

          // this disables the browsers default copy functionality
          event.preventDefault()

          // perform desired action(s) here...
          console.log('The CTRL key and the C key are being pressed simultaneously.');

        }

        if (ctrlActive == true && event.code == 'KeyV') {

          // this disables the browsers default paste functionality
          event.preventDefault()

          // perform desired action(s) here...
          console.log('The CTRL key and the V key are being pressed simultaneously.');
        }

      })