如何监听键盘按键 – 千丝海阁

首页 » 黑莓开发 » 如何监听键盘按键

如何监听键盘按键

2444 0

我们做程序往往需要做程序内部的快捷键,比如PC浏览器的F5均为刷新按键,同样黑莓的程序,如有必要也需要设置这样的快捷键,就像BBextra那样,进入菜单后,可以按p进入通话增强,按i进入彩灯增强。

在程序运行的当前screen下加入
public boolean keyChar(char key, int status, int time) {
if (key == Characters.LATIN_CAPITAL_LETTER_P || key == Characters.LATIN_SMALL_LETTER_P)
myList.setSelectedIndex(0);
if (key == Characters.LATIN_CAPITAL_LETTER_C || key == Characters.LATIN_SMALL_LETTER_C)
myList.setSelectedIndex(2);
if (key == Characters.LATIN_CAPITAL_LETTER_L || key == Characters.LATIN_SMALL_LETTER_L)
myList.setSelectedIndex(1);
if (key == Characters.LATIN_CAPITAL_LETTER_W || key == Characters.LATIN_SMALL_LETTER_W)
myList.setSelectedIndex(3);
if (key == Characters.LATIN_CAPITAL_LETTER_T || key == Characters.LATIN_SMALL_LETTER_T)
myList.setSelectedIndex(4);
if (key == Characters.LATIN_CAPITAL_LETTER_O || key == Characters.LATIN_SMALL_LETTER_O)
myList.setSelectedIndex(7);
if (key == Characters.LATIN_CAPITAL_LETTER_F || key == Characters.LATIN_SMALL_LETTER_F)
myList.setSelectedIndex(6);
if (key == Characters.LATIN_CAPITAL_LETTER_A || key == Characters.LATIN_SMALL_LETTER_A)
myList.setSelectedIndex(5);
if (key == Characters.ENTER) {
if (myList.getSelectedIndex() == 0)
UiApplication.getUiApplication().pushScreen(new ascreen());
else if (myList.getSelectedIndex() == 1)
UiApplication.getUiApplication().pushScreen(new ascreen2());
else if (myList.getSelectedIndex() == 2)
UiApplication.getUiApplication().pushScreen(new ascreen3());
else if (myList.getSelectedIndex() == 3)
UiApplication.getUiApplication().pushScreen(new ascreen4());
else if (myList.getSelectedIndex() == 4)
UiApplication.getUiApplication().pushScreen(new ascreen5());
else if (myList.getSelectedIndex() == 5)
UiApplication.getUiApplication().pushScreen(new ascreen8());
else if (myList.getSelectedIndex() == 6)
UiApplication.getUiApplication().pushScreen(new ascreen7());
else if (myList.getSelectedIndex() == 7)
UiApplication.getUiApplication().pushScreen(new ascreen6());
return true;
}
return false;
}

用以监听快捷键是否被用户按下,并切换到各自子屏幕。
PS:配图的快捷键和上述代码有出入,请自行调整。
如果要监听照相机键等非ABCD的键,则可以使用keyDown(int keycode, int time)或者keyUp(int keycode, int time)来进行判断。

文章评分1次,平均分5.0



上一篇:[转]用黑莓MDS方式下载大文件
下一篇:用win7自带磁盘管理器进行分区

本文原始地址:http://www.tiandiyoyo.com/2011/10/how-to-capture-keypress/
本站所有文章,除了特别注明外,均为本站原创,转载请注明出处来自www.tiandiyoyo.com

您可能还会对以下文章感兴趣:

评论前先开启评论开关:


//