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 8471213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:44:06+00:00 2026-06-10T16:44:06+00:00

Please suggest the best way to create key events for HTML5 canvas. I don’t

  • 0

Please suggest the best way to create key events for HTML5 canvas. I don’t prefer any library, but if you think that it’s the best way then go answer it. Thanks in advance!

  • 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-10T16:44:08+00:00Added an answer on June 10, 2026 at 4:44 pm

    This will return the key code:

    <canvas id="myCanvas" width="200" height="100" style="background:green"></canvas>
    <script type="text/javascript">
    window.addEventListener('keydown',this.check,false);
    
    function check(e) {
        alert(e.keyCode);
    }
    </script>
    

    If you would like a demonstration of different things being done based on key:

    function check(e) {
        var code = e.keyCode;
        //Up arrow pressed
        if (code == 38)
            alert("You pressed the Up arrow key");
        else
            alert("You pressed some other key I don't really care about.");
    }
    

    Or if you have a long list of keys you’ll be using, do it in a switch case:

    function check(e) {
        var code = e.keyCode;
        switch (code) {
            case 37: alert("Left"); break; //Left key
            case 38: alert("Up"); break; //Up key
            case 39: alert("Right"); break; //Right key
            case 40: alert("Down"); break; //Down key
            default: alert(code); //Everything else
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please suggest me the best authentication way to implement in the scenario mentioned below:
Can you please suggest to me the best way to make a Multilingual Website
Please suggest the best way of solving memory leaks on the iphone. What is
Please suggest the best way in which we encrypt in JavaScript and decrypt in
Can you please suggest me, best way to show pdf files in iphone since
Please suggest the best way for me. I want to change the default filter's
I am very new to Ruby so could you please suggest the best practice
Please suggest a way to auto format all py files in an eclipse project
I need to create multilingual help (.chm) file for my WPF application. Please suggest
Please suggest or change some suitlable title for this question as i am not

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.