dcsimg
A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: wont respond to keyboard up left and space, at the same time

  1. #1
    Senior Member
    Join Date
    Jul 2008
    Posts
    418

    wont respond to keyboard up left and space, at the same time

    Hello, I have 2 functions for releasing and pressing keys, for the 5 buttons: arrow buttons and space. there are no problems at all when i dont press space, everything works. but when I press space, and then left and up at the same time, the last 2 wont respond. if i press either of them first, and then the other after that, only the last one of them wont respond. strangely, this doesnt happen when i press left and down, right and down, or up and right. only with left and up.
    these are the functions:
    PHP Code:
    protected function keyPressed(e:KeyboardEvent):void
            
    {
                if (
    Boolean(keysDown[e.keyCode]))
                    {return;}
                
    keysDown[e.keyCode] = true;
                switch (
    e.keyCode)
                {
                    case (
    LEFT)://arrow-left
                        
    kine.setHSpeed(-SPEED);
                        break;
                    case (
    UP)://arrow-up
                        
    kine.setVSpeed(-SPEED);
                        break;
                    case (
    RIGHT)://arrow-right
                        
    kine.setHSpeed(SPEED);
                        break;
                    case (
    DOWN)://arrow-down
                        
    kine.setVSpeed(SPEED);
                        break;
                    case (
    SPACE)://shift
                        
    weapon.shoot(x,y);
                        
    shootTimer.start();
                        break;
                    default:
                        return;
                }
            } 
    and for releasing:
    PHP Code:
    protected function keyReleased(e:KeyboardEvent):void
            
    {
                
    keysDown[e.keyCode] = false;
                switch (
    e.keyCode)
                {
                    case (
    LEFT)://arrow-left
                        //trace("left key released");
                        
    if (keysDown[RIGHT])
                        {
                            
    kine.setHSpeed(SPEED);
                        }
                        else
                        {
                            
    kine.setHSpeed(0);
                        }
                        break;
                    case (
    UP)://arrow-up
                        //trace("up key released");
                        
    if (keysDown[DOWN])
                        {
                            
    kine.setVSpeed(SPEED);
                        }
                        else
                        {
                            
    kine.setVSpeed(0);
                        }
                        break;
                    case (
    RIGHT)://arrow-right
                        //trace("right key released");
                        
    if (keysDown[LEFT])
                        {
                            
    kine.setHSpeed(-SPEED);
                        }
                        else
                        {
                            
    kine.setHSpeed(0);
                        }
                        break;
                    case (
    DOWN)://arrow-down
                        //trace("down key released");
                        
    if (keysDown[UP])
                        {
                            
    kine.setVSpeed(-SPEED);
                        }
                        else
                        {
                            
    kine.setVSpeed(0);
                        }
                        break;
                    case (
    SPACE)://shift
                        
    shootTimer.reset();
                        break;
                }
            } 
    I cant find the problem atall. have been looking for it quite some time.

    Thanks, in advance.

  2. #2
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    The good news: It's not your code that's the problem.

    The bad news: You have a cheap keyboard.

  3. #3
    Senior Member
    Join Date
    Jul 2008
    Posts
    418
    how many % of the people have this same problem?

    and what really is causing this, a mistake in production?

  4. #4
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    It's quite common, especially on the arrow keys. Most keyboards only register three arrow keys at a time, or 4 non-arrows.

    Here's a page which explains why it happens:
    http://www.dribin.org/dave/keyboard/one_html/

    Keyboard manufacturers are too cheap to use a design which handles the issue, because it is quite rare in practice.

  5. #5
    Senior Member
    Join Date
    Jul 2008
    Posts
    418
    How do i solve this? use another key than space? I'd rather not.
    is it the same key combination with every keyboard?

  6. #6
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    My understanding is that it varies by keyboard model. Some will have different combinations than others. You might try using WASD instead of the arrows, or allowing the user to set their own key mappings.

  7. #7
    Senior Member
    Join Date
    Jul 2008
    Posts
    418
    will control work instead of space? or are there problems with this, such as that control and arrow key means a certain operation in the browser? alt maybe? i know shift won't work, since it makes some kine of 7 secs shift key mode blabla popup appear. I'd rather not use wasd, unless it's absolutely neccesairy.
    I really prefer arrow keys and space, but i guess thats not gonna work.

  8. #8
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Any particular combination of 3 or more keys at once could screw up on some keyboards.

  9. #9
    Junior Member
    Join Date
    Dec 2006
    Location
    San Francisco, Ca
    Posts
    10
    CasaLib's Key class has worked very well for us in the past:
    http://casalib.org/blog/using-the-key-class/

  10. #10
    Senior Member
    Join Date
    Sep 2008
    Posts
    121
    Just ran into this problem aswell . Got an expensive Dell laptop, pretty new, top-notch...... but in my game, I can't jump to the left and shoot (up+left+space).... all other directions works, like jumping to the right and shoot (up+right+space). Of course, replacing space (shoot) with any other key works... but meh.... not comfy to shoot with any other key..... guess I have to add some sort of set-your-own-keys in options.

    In other words, on this keyboard, space will not work if I hold left and up on the arrow keys.... but ALL other combinations works.
    Last edited by Geneve; 05-08-2009 at 06:56 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center