Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6963091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:44:41+00:00 2026-05-27T15:44:41+00:00

so right now I’m using a function that will set a value to true

  • 0

so right now I’m using a function that will set a value to true if one key being pressed, another being pressed regardless of whether or not the first one is still depressed.

 function doc_keyUp1(e) {
      if (e.keyCode == 37){
        lPunch = true 
      }
  }
  function doc_keyUp2(e) {
      if (e.keyCode == 39){
        rPunch = true
      }
  }
  document.addEventListener('keyup', doc_keyUp1, false)
  document.addEventListener('keyup', doc_keyUp2, false)

The thing is, I want to be able to have it make sure that if the second key is being pressed, that the first one must still be down, so that someone can’t just press one then the other quickly and make it seem as if they were both pressed down at the same time.

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T15:44:42+00:00Added an answer on May 27, 2026 at 3:44 pm

    Assuming you have some kind of “game loop” something like the following works (or perhaps I should say “should work”, in that I haven’t coded something like this for a long time and so haven’t tested it with current browsers – definitely used to work):

    var keyPressed = {};
    
    document.addEventListener('keydown', function(e) {
       keyPressed[e.keyCode] = true;
    }, false);
    document.addEventListener('keyup', function(e) {
       keyPressed[e.keyCode] = false;
    }, false);
    
    function gameLoop() {
       if (keyPressed["39"] && keyPressed["37"]) {
          // do something (update player object state, whatever)
       }
       // etc
       // update display here
       setTimeout(gameLoop, 5);
    }
    
    gameLoop();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Right now I can call a method using ajax (:remote=> 'true') at awisprotect_path by
Right now, I keep all of my projects on my laptop. I'm thinking that
Right now I have an SSIS package that runs every morning and gives me
Right now, I have code that looks something like this: Private Sub ShowReport(ByVal reportName
Right now I am using this code to download files (with a Range header).
Right now I'm using Controller_Template would like to have RESTful URLs though, is it
Right now, I'm trying to separate out a set of constantly changing classes into
Right now I've been using GDB to disassemble a binary file and check out
Right now, I have three models Post, Comment and User (using Devise ) associated
right now i have this <script type='text/javascript'> $(#beau).click(function(){ $(#beau).animate({margin-Top: 738px}, fast); }); </script> and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.