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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:51:55+00:00 2026-05-30T23:51:55+00:00

I found a script that can handle input for a small HTML5 based game

  • 0

I found a script that can handle input for a small HTML5 based game I’m building:

var KEY = {W: 87, A: 65, S:83, D: 68, E: 69};

var input = {
    right: false,
    up: false,
    left: false,
    down: false,
    e: false
};

function press() 
{
    if (!ni)
    {
        var evt=window.event;
        var code = evt.keyCode;

        switch(code) 
        {
            case KEY.W: input.up = true; break;
            case KEY.A: input.left = true; break;
            case KEY.S: input.down = true; break;
            case KEY.D: input.right = true; break;
            case KEY.E: input.e = true; break;
        }
    }
}

function release()
{
    if (!ni)
    {
        evt=window.event;
        var code = evt.keyCode; 
        input.code = code;

        switch(code) 
        {
            case KEY.W: input.up = false; break;
            case KEY.A: input.left = false; break;
            case KEY.S: input.down = false; break;
            case KEY.D: input.right = false; break;        
            case KEY.E: input.e = false; break;
        }
    }
}

This is how the event handlers are assigned:

document.addEventListener("keydown", press);
document.addEventListener("keyup", release);

The variable ni that shows up occasionally is true when the player is entering text in a text box, I’m pretty sure that it isn’t causing the problems. Also, this works perfectly in chrome, but as I said, doesn’t work in Firefox. Anybody care to explain why? Firefox version: 10.0.2.4428.

  • 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-30T23:51:56+00:00Added an answer on May 30, 2026 at 11:51 pm

    The non-standard window.event object is only available in IE and Chrome.

    In standard-compliant browsers, the event object is passed as a first argument to the event listener.

    Change:

    function press() {
        if (!ni) {
            var evt=window.event;
    

    to:

    function press(evt) {              // <-- Declaration of evt
        if (!ni) {
            evt = evt || window.event; // <-- Notice: var is omitted
    

    Equivalently:

    function release(evt) {
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I found a perl script that manages randomizing the wikipedia articles in Wikipedia here
The only reliable method that I a have found for using a script to
I found this script: <script language=Javascript TYPE=text/javascript> var container = document.getElementById('dl'); var seconds =
How can I write text entities to a dxf file? I found a script
EDIT: The entire code and database creation script can be found from http://gitorious.org/scheator .
I'm building a class or two based on StdRegProv to handle Windows Registry via
i looking to make a small script that will understand pagination of urls i
I downloaded FPDF 1.7 and found a script based on the Avery 5160 standards
I found a script which has the following snippet:- userid=`expr \`id\` : .*uid=[0-9]*(\(.[0-9a-z]*\)) .*`
I wanted to use groovy for a little ftp script and found this post

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.