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

  • SEARCH
  • Home
  • 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 7818929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T06:44:25+00:00 2026-06-02T06:44:25+00:00

whenever i press on either up or down button i can check if those

  • 0

whenever i press on either up or down button i can check if those key were pressed for example an alert will be fired here :

 if ((38 in keysDown) ) { // Player holding up

       window.alert("up button was pressed");
 }


 if ((40 in keysDown) ) { // Player holding down

       window.alert("down button was pressed");
 }

but here even tho i press on enter the alert doesnt play

if ((13 in keysDown) ) { // player pushed on enter
       window.alert("enter key was pressed"); // here nothing happen
}

i am using those 3 lines right at the start to add a event listner:

   keysDown = {};
   addEventListener("keydown", function (e) {keysDown[e.keyCode] = true;}, false);
   addEventListener("keyup", function (e) {delete keysDown[e.keyCode];}, false);

but for some reason which i dont know of the enter key doesnt work
the problem occurs on firefox , working fine on Chrome and on IE

thanks in advance.

EDIT i figure out the problem, the canvas which i am using doesnt have focus,
so the enter button doesnt work, can any1 tell me how to switch focus ?

  • 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-06-02T06:44:26+00:00Added an answer on June 2, 2026 at 6:44 am

    EDIT i figure out the problem, the canvas which i am using doesnt have
    focus, so the enter button doesnt work, can any1 tell me how to switch
    focus ?

    sure.
    How do you set focus to the HTML5 canvas element?

    or even better:

    1- Tabindex:

    $("#canvas")
        // Add tab index to ensure the canvas retains focus
        .attr("tabindex", "0")
        // Mouse down override to prevent default browser controls from appearing
        .mousedown(function(){ $(this).focus(); return false; }) 
        .keydown(function(){ /* ... bla bla bla ... */ return false; });
    

    2- setting contentEditable to true:

    // Add content editable to help ensure the canvas retains focus
    $("#canvas").attr("contentEditable", "true")
    $("#canvas")[0].contentEditable = true;
    

    source: How do I give an HTML canvas the keyboard focus using jquery?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

is it possible to hide tab and whenever I press a button it will
Whenever you press comment on facebook, u can see the page move to textarea
Whenever i press the Back or previous button on the blackberry simulator everytime it
I want to get alerted whenever I press a key. I've tried: $('body').live('keyup', function()
I have an EditField in my program. whenever i press the 'sym' key on
Hi friends, whenever I press the numbers in textfield it's take upto 9 numbers
I'm working on a word-press theme and whenever I add the code below to,
I've gotten used to , when i press M-x that whenever i type a
whenever i needed to test my web site, i used to press ctrl and
Whenever I press Ctrl + S in eclipse to save source code I want

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.