Ignis
Ignis

Reputation: 3

J2ME GameCanvas recognizing keys

I want to recognize some keys in my J2ME project - namely the star (*) key or the command buttons. getKeyStates() doesn't work, and even when I used keyPressed() (or keyReleased(), which is incredibly slow) it doesn't recognize the key.

It seems that NetBeans doesn't even recognize the star key as a valid key press (as in, doesn't call the keyPressed event.)

My code is:

protected void keyPressed(int keyCode)
{
    int ga = getGameAction(keyCode);

    switch (ga)
    {
        case (LEFT):
        {
        }
        break;

        case (RIGHT):
        {
        }
        break;

        case (DOWN):
        {

        }
        break;

        case (UP):
        {
        }
        break;

        case (KEY_STAR):
        {
        }
        break;

        case (KeySoft1):
        {
        }
        break;
    }

    switch (keyCode)
    {
        case (KeyFire):
        {
            //Act accordigly to the situation.
            fbButton.FirePressed();
        }
        break;

        case (KeySoft1):
        {
            fbButton.FirePressed();
        }
        break;
    }
}

I'm using NetBeans 6.5.1, MIDP 2.0.

Upvotes: 0

Views: 614

Answers (1)

funkybro
funkybro

Reputation: 8671

Canvas.KEY_STAR is a keyCode rather than a gameAction.

if (keyCode == Canvas.KEY_STAR) {
    System.out.println("That's the Star");
}

Upvotes: 1

Related Questions