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

286
Views
Making a button which on press or click executive a function until unpress the buttons

Here the thing I m trying to make an object move using HTML button but in click it exicute the function ones I want it to exicute the function continuously on press of button Below is the code for the button in JavaScript

var increment = 1; 

function moveUp()
{
camera.position.z +=increment;
}
function moveDown()
{
camera.position.z -= increment;
}
function moveRight()
{
camera.position.x +=increment;
}
function moveLeft()
{
camera.position.x -= increment;
}

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

0

You should use the events.

  1. Detect the keyDown event. Set a variable 'buttonUpIsDown'=true and call -or set a timer to call every 10ms- a function.
  2. While/If (buttonUpIsDown) { increment stuff};
  3. Detect the keyUp event and put the variable back to false.

https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent

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!