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

134
Views
Comparison of key press and string

I am doing an experiment and I want a part to be shown if a certain key ("b") is pressed and skipped, if any other key is pressed. The key that is pressed is saved in key_resp_3.keys and if I visualize what's saved in the key_resp_3.keys variable it's simply b. So I thought this would be the right comparison:

    if ((key_resp_3.keys != "b")) {
        continueRoutine = false;
    }

However in this case, the routine is always skipped so somehow "b" is obviously not the way the key is saved in the key_resp_3.keys variable. Does anyone have an idea what is the right comparison instead?

Thank you!

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

0

Hard to tell the root cause of the problem without the rest of the code. But you can simply use an event listener like below

document.addEventListener('keydown', function(event) {
    console.log(event.key)
    
    const key = event.key
    if(key == "b")
      alert("b presed")    
});

Or can it be as simple as you are trying to set const key_resp_3 = event.key then checking in the if key_resp_3.keys so you are trying to access variable.key.key

In this special case: since the keys is a array you can use

Does contains b
key_resp_3.keys.includes('b')

Does not contains b
!key_resp_3.keys.includes('b')
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!