×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    Jun 2010
    Posts
    5

    UP and DOWN, 2 and 8 clashing.

    I have in my code

    Code:
    protected void keyPressed(int keyCode)
    {
            int key = getGameAction(keyCode);
    
           password.keyPressed(keyCode, textAndNum, 12);
    password.keyPressed being a text input class I wrote for use with canvas, takes a number key and draws the corresponding txt on screen, but i noticed that also it would keep moving down or up everytime I pressed 2 or 8 and after checking it with a breakpoint it does in fact clash.
    The code that clashes is as follows.

    Code:
     switch (getGameAction(keyCode))
            {
                case UP:
    // code clash
    This is nokia specific only, or at least i believe so as it doesn't happen when using the standard java netbeans emulator.
    Any help would be appreciated, thanks.

  2. #2
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Re: UP and DOWN, 2 and 8 clashing.

    Welcome to the Forum Nokia Discussion Boards...

    That the normal and correct behaviour of the MIDlet, and in order to get rid of the same you can comment the codelet int key = getGameAction(keyCode); and you directly pass the keyCode to the line password.keyPressed(keyCode, textAndNum, 12);.

    Test the same and let us know the results.

    If you will read the WTK docs and there you will find that:
    Portable applications that are interested in using game actions should translate every key event into a game action by calling the getGameAction() method and then testing the result. For example, on some devices the game actions UP, DOWN, LEFT and RIGHT may be mapped to 4-way navigation arrow keys. In this case, getKeyCode(UP) would return a device-dependent code for the up-arrow key. On other devices, a possible mapping would be on the number keys 2, 4, 6 and 8. In this case, getKeyCode(UP) would return KEY_NUM2. In both cases, the getGameAction() method would return the LEFT game action when the user presses the key that is a "natural left" on her device.
    I think that this is the enough information for your concern
    Last edited by raj_J2ME; 2010-08-10 at 13:03. Reason: added more words
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  3. #3
    Registered User
    Join Date
    Jun 2010
    Posts
    5

    Re: UP and DOWN, 2 and 8 clashing.

    Am I not passing keyCode in directly already?
    This code
    Code:
    int key = getGameAction(keyCode);
    is not used in these examples, it is used elsewhere however in my code, though I have tried using the getGameAction for my own text input class, example.

    Code:
    int key = getGameAction(keyCode);
    password.keyPressed(key, textAndNum, 12);
    but the numeric keypad will not take any input.

    this was what it is now
    Code:
    int key = getGameAction(keyCode);
    password.keyPressed(keyCode, textAndNum, 12);
    key is not used.

    I have also tried
    Code:
     switch (keyCode)
            {
                case UP:
    // code clash
    Code:
     switch (keyCode)
            {
                case Canvas.UP:
    // code clash
    passing keyCode directly to the switch statement instead of game actions but that obviously won't and didn't work either. I need both direct keycode to handle the numeric keys and get game action for the up and down.
    Last edited by Gunblade; 2010-08-10 at 13:57. Reason: wording changes

  4. #4
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: UP and DOWN, 2 and 8 clashing.

    I strongly recommend you avoid using getGameAction(), instead using the original key code. Values for this are documented in the developer's library.

    Game actions cause a variety of problems, such as mapping of multiple keys to one action, and inconsistent mapping of actions to keys across devices (for example, which key is FIRE - dpad centre? Left soft key? 5? 0? SEND? Some combination?)

    If you really must use game actions, eliminate "regular" keys first:

    Code:
    switch (keycode) {
    case KEY_NUM0:
        break;
    case KEY_NUM1:
        break;
    case KEY_NUM2:
        break;
    case KEY_NUM3:
        break;
    case KEY_NUM4:
        break;
    case KEY_NUM5:
        break;
    case KEY_NUM6:
        break;
    case KEY_NUM7:
        break;
    case KEY_NUM8:
        break;
    case KEY_NUM9:
        break;
    case KEY_POUND:
        break;
    case KEY_STAR:
        break;
    default:
        int action = getGameAction(keycode);
        switch (action) {
        case UP:
            break;
        case DOWN:
            break;
        case LEFT:
            break;
        case RIGHT:
            break;
        case FIRE:
            break;
        }
        break;
    }
    Graham.

  5. #5
    Registered User
    Join Date
    Jun 2010
    Posts
    5

    Re: UP and DOWN, 2 and 8 clashing.

    Ah yeah got it sorted, i just got rid of getGameAction being that it isn't really neccessary but thanks for the input, i'll keep that in mind for any code i need next time ^^

Posting Permissions

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