Kris
Kris

Reputation: 921

How to get a native keypad in game.?

i have a game developed using LWUIT.now i am implementing full touch in game.it is a multi player game so there are some options like chat and login. when we press on chat we need to enter the characters in the field. my question is

is it possible to invoke the native keypad when we press on the chat button .?

thanks in advance kris

Upvotes: 1

Views: 216

Answers (1)

Shai Almog
Shai Almog

Reputation: 52770

No. MIDP doesn't include such an API. You can use LWUIT's virtual keyboard (which isn't native) and define any character set you want as explained here: http://lwuit.blogspot.com/2010/06/pimp-virtualkeyboard-by-chen-fishbein.html

You can show it using the display class.

On Symbian devices if you do not define some jad properties, a touch keypad will be always visible and you won't be able to hide it for more details look here: http://lwuit.blogspot.com/2009/11/optimized-for-touch.html

Looking at the question again I'm thinking the VKB is probably an overkill for an always on keypad replacement. Just place your content in the center of a BorderLayout and stick a container in the south something like this:

addComponent(BorderLayout.CENTER, myUI);
Container keypad = new Container(new GridLayout(2, 2));
addComponent(BorderLayout.SOUTH, keypad);
Button up = new Button("Up");
Button down = new Button("Down");
Button left = new Button("Left");
Button right = new Button("Right");
up.setFocusable(false);
down.setFocusable(false);
left.setFocusable(false);
right.setFocusable(false);
keypad.addComponent(up);
keypad.addComponent(down);
keypad.addComponent(left);
keypad.addComponent(right);
up.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent ev) {
       int up = Display.getInstance().getKeyCode(Display.GAME_UP);
       Display.getInstance().getCurrentForm().keyPressed(up);
       Display.getInstance().getCurrentForm().keyReleased(up);
    }
});

The rest and fire are pretty trivial to add (same thing) notice that getKeyCode is deprecated but should work for now since we have no alternative to that API.

Upvotes: 1

Related Questions