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

152
Views
How to launch a function when an event stop?

Anyone knows how I cant check when an event stop?

Im coding a game just to learn how to use the canvas tag on HTML. To make player move, Im using switch case like this:

switch (event.code) {
case 'ArrowUp':
  // code
  break;
case 'ArrowDown':
  break;
case 'ArrowRight':
  // code
  break;
case 'ArrowLeft':
  // code
default:
  break;}

But I need to launch a function when the user stop to press the key.

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

0

To do this I got use a event listener with the parameter "keyup"

document.body.addEventListener('keyup',()=>{
    // function
};
about 4 years ago · Juan Pablo Isaza Report

0

document.addEventListener('mousedown', function(event) {
  console.log('clicked', event.code);
  switch (event.code) {
case 'ArrowUp':
  // code
  break;
case 'ArrowDown':
  break;
case 'ArrowRight':
  // code
  break;
case 'ArrowLeft':
  // code
default:
  break;}
})
document.addEventListener('keyup', function() {
  console.log('key not pressed');
})

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!