Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Logging happens when Shift+key is pressed

Maybe someone can guide me in the right direction. I am trying to make logging happen if the Shift+key is pressed and not happen if only the Shift is pressed.

At the moment it works as expected, except that when I press Shift it also gets logged 🙁 Also tried to console.log(event.shiftKey) but then getting "true" logged

document.addEventListener('keydown', (event)=> {    
    if(event.shiftKey && event.key) {
      console.log(event.key)
    } 
})

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Check key is not equal to shift

document.addEventListener('keydown', (event) => {
  if (event.shiftKey && event.key !== "Shift") {
    console.log(event.key)
  }
})
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading