Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

126
Views
using Shift + Enter key to run a function

I'm kind of new to JS, I have searched the internet and I haven't got what I'm looking for, I want to run a function if the keys Shift and Enter were pressed, like a shortcut, I have tried this but I think I killed JS with this code

document.addEventListener('keypress', function (e) {
    if (e.key === 'Enter' + 'Shift') {

       console.log("test");
    }
});

anything would be helpful, thanks.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You can use e.shiftKey to see if shift is being pressed.

document.addEventListener('keypress', function(e) {
  if (e.key === 'Enter' && e.shiftKey) {
    console.log("test");
  }
});

about 4 years ago · Juan Pablo Isaza Report

0

This is a pretty expandable solution because you can create shortcuts for many different keys.

const keysDown = {};
document.addEventListener('keydown', ({ key }) => {
  keysDown[key] = true;
  if (keysDown.Shift && keysDown.Enter) console.log("test");
});
document.addEventListener('keyup', ({ key }) => {
  keysDown[key] = false;
});

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!