×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Nov 2003
    Posts
    13

    Keyboard Keys not working properly?

    Is it a Canvas/Fullcanvas/GameCanvas bug?? or is it all emulators wrong???

    I use like:

    protected void keyPressed( int keyCode ){
    teclaPressionada=keyCode;
    }

    and i test like

    switch(teclaPressionada){
    case LEFT: nivel.getRaquete().move(-3);
    break;
    case RIGHT: nivel.getRaquete().move(3);
    break;
    }

    this doesn't work...
    i have insert a println and LEFT corresponds to 2 and Right to 5
    and when i press the left arrow the keyCode is -4 and right -3

    What is wrong here? Is it my code??

    Regards

  2. #2
    Super Contributor
    Join Date
    Mar 2003
    Location
    Israel
    Posts
    2,280
    LEFT, RIGHT, UP, DOWN, FIRE, GAME_A, GAME_B, etc. are game actions, not key codes. You have to convert the key code into a game action with getGameAction().
    Code:
    protected void keyPressed( int keyCode ){
    // I kept this in case you have to test stuff that isn't a game action
    teclaPressionada=keyCode;
    // and here is what you want
    accionPressionada=getGameAction(keyCode);
    }
    
    // ....
    // using the game action
    switch(accionPressionada){
    case LEFT: nivel.getRaquete().move(-3);
    break;
    case RIGHT: nivel.getRaquete().move(3);
    break;
    }
    // using a key code
    switch(teclaPressionada){
    case KEY_STAR: // something
    break;
    case KEY_NUM0: // something else
    break;
    }
    shmoove

  3. #3
    Registered User
    Join Date
    Nov 2003
    Posts
    13
    Thanks mate

    I really apreciated that post hehehe!

    My mind was numb and i didn't notice that little "big" detail ;P

    Regards

Posting Permissions

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