Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript bug? No space bar event when pressing up and left arrow keys

I'm developing a little game and I try to receive the key input from arrow up, down,left, right and space.

On keyDown i set some booleans to true und on keyDown to false again. In the main loop I check those booleans, so the character can move in 1 of 8 directions and shoot at the same time.

Everything works: North-East + Space, South-East + Space, South-West + Space but North-West + Space doesn't work. The event for the space bar doesn't get fired.

 function onKeyDown(evt){

            switch(evt.keyCode){

                case up:
                pressedUp=true;
                break;

                case right:
                pressedRight = true;
                break;

                case down:
                pressedDown = true;
                break;

                case left:
                pressedLeft = true;
                break;

                case space:
                spacePressed=true;
                break;
            }

            updateCamera();
        }

        function onKeyUp(evt){

           switch(evt.keyCode){
                 case up:
                pressedUp=false;
                break;

                case right:
                pressedRight = false;
                break;

                case down:
                pressedDown = false;
                break;

                case left:
                pressedLeft = false;
                break;

                case space:
                spacePressed = false;
                break;
            }
        }
like image 639
Dominic Avatar asked Sep 19 '25 10:09

Dominic


1 Answers

I did some tests and I have the same behaviour throughout all browsers as well as in Flash and AIR applications, so for me it's very likely caused by my Keyboard (Model: Cherry JK-0100DE).

My workaround is to use another key instead of Space - probably going with X or Y.

like image 104
olsn Avatar answered Sep 21 '25 02:09

olsn