如何在游戏中获得原生键盘?

问题描述:

我有一款使用LWUIT开发的游戏,现在我在游戏中实现全面触控。它是一款多人游戏,所以有一些选项,如聊天和登录。当我们按下聊天时,我们需要输入字段中的字符。我的问题是如何在游戏中获得原生键盘?

当我们按下聊天按钮时,是否可以调用本机键盘?

由于事先 克里斯

号MIDP不包括这样的API。您可以使用LWUIT的虚拟键盘(非本机键盘)并按照此处所述定义所需的任何字符集: http://lwuit.blogspot.com/2010/06/pimp-virtualkeyboard-by-chen-fishbein.html

您可以使用display class来显示它。

在Symbian设备上,如果你不定义一些JAD特性,触摸键盘将始终可见,并且您将无法将其隐藏更多细节看这里: http://lwuit.blogspot.com/2009/11/optimized-for-touch.html

再次在问题展望我认为VKB可能是一个永远在线的键盘替代品的矫枉过正。只要将您的内容在BorderLayout的中心和南部像这样坚持一个容器:

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); 
    } 
}); 

的休息和火是相当容易加入(同样的事情)注意到getKeyCode已被弃用,但应对工作现在,因为我们没有替代该API。

+0

嗨Shai Almog谢谢你的支持。你可以给我一个样品midlet什么的,所以我可以很容易地理解如何调用LWUIT vkeypad。这将是非常有帮助的。 – Kris 2011-05-23 04:56:08

+1

我更新了我的答案,以反映您的问题的更简单的解决方案 – 2011-05-23 07:46:01