识别 bb 中按下的是哪个键
我试图识别按下了哪个键并根据需要执行操作。基本上使用它们在按“i”和“o”时执行放大和缩小。
我用过这些方法:
protected boolean keyDown(int keycode, int time)
{
int key=Keypad.key(keycode);
String keyC=Integer.toString(key);
System.out.println("********************************* key pressed"+key);
System.out.println("********************************* key pressed to string"+keyC);
return super.keyDown(keycode, time);
}
public boolean keyChar(char key, int status, int time)
{
System.out.println("inside keychar");
boolean retval = false;
int zoom=mapField.mf.getZoom();
if(key== 'o'||key== 'O')
{
zoom=zoom-3;
mapField.mf.setZoom(zoom);
retval = true;
}
super.mf.setZoom(zoom);
return retval;
}
这些方法似乎根本不起作用。
I am trying to recognise which key is pressed and do the action as required. Basically using them to perform zoom in n zoom out on the press of "i" n "o".
I have used these methods:
protected boolean keyDown(int keycode, int time)
{
int key=Keypad.key(keycode);
String keyC=Integer.toString(key);
System.out.println("********************************* key pressed"+key);
System.out.println("********************************* key pressed to string"+keyC);
return super.keyDown(keycode, time);
}
public boolean keyChar(char key, int status, int time)
{
System.out.println("inside keychar");
boolean retval = false;
int zoom=mapField.mf.getZoom();
if(key== 'o'||key== 'O')
{
zoom=zoom-3;
mapField.mf.setZoom(zoom);
retval = true;
}
super.mf.setZoom(zoom);
return retval;
}
these methods dont seem to work at all.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,让我告诉你我会怎么做,希望在某个地方会有一个顿悟的时刻。
然后在您的应用程序构造函数中
“应用程序应使用 keyChar 通知来确定用户按下了哪些字符”是 www.blackberry.com 在其 API 中的建议。
另外,请确保代码中的其他位置没有其他 keyChar 方法。如果有,那么您期望被调用的这个将不会被调用。
另外,不要使用 key=='o' 尝试使用 net.rim.device.api.system.Characters 中的一些值来查看是否有一些您可以获得的键,例如
哦,一个最后一次尝试。您可以看看是否
也能改善您的情况。
抱歉,目前我面前既没有模拟器也没有设备,所以我无法与您一起运行这些程序,但希望我已经解决了其中一个问题。
Ok let me give you how I would do it and hopefully there will be an aha moment somewhere.
Then in your application constructor
"apps should use the keyChar notification to determine which characters a user has pressed" is the recommendation from www.blackberry.com in their API.
Also, make sure there are no other keyChar methods lying around elsewhere in your code. If there are, then this one you are expecting to be called will not be called.
Also instead of key=='o' try to use some of the values from net.rim.device.api.system.Characters to see if there are some keys you can get for example
Oh, one last try. You could see if
improves your situation as well.
Sorry I have neither a simulator nor a device in front of me at the moment so I cannot run these with you, but hopefully I have hit on the issue with one of these.