黑莓手机 - 的KeyListener具有全局范围 [英] BlackBerry - KeyListener with global scope

查看:196
本文介绍了黑莓手机 - 的KeyListener具有全局范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新黑莓应用程序的开发。我希望能够监听键preSS事件每当黑莓(8900在我的情况)是和在所有屏幕上这可能吗?

I am new to BlackBerry App development. I want to be able to listen for keypress events whenever the BlackBerry (8900 in my case) is on and on all screens is this possible?

如果是这样,这将是伟大的人直接在我的方向是正确的。我已经在看看接口的KeyListener。

If so, it would be great for someone to direct me in the right direction. I am already having a look at Interface KeyListener.

import net.rim.device.api.system.*;

感谢所有

推荐答案

实施一个keylistenerClass,如:

进口model.Profile;

import model.Profile;

import net.rim.device.api.system.KeyListener;
import net.rim.device.api.ui.Keypad;


public final class ShortcutHandler implements KeyListener {

    public boolean keyChar(char key, int status, int time) {
        return false;
    }

    public boolean keyDown(int keycode, int time) {
        if (Keypad.KEY_ESCAPE == Keypad.key(keycode)) {
                        // Consume the event.
                        // Here I'm consuming the event for the escape key
            return true;
        }
                //let the system to pass the event to another listener.
        return false;
    }

    public boolean keyRepeat(int keycode, int time) {
        return false;
    }

    public boolean keyStatus(int keycode, int time) {
        return false;
    }

    public boolean keyUp(int keycode, int time) {
        return false;
    }

}

然后在你的应用程序构造

public Application() {

    //Add the listener to the system for this application
    addKeyListener(new ShortcutHandler());
}

我可以证实,它的工作时,应用程序在后台运行。

I confirm that it's working when the application is in the background.

这篇关于黑莓手机 - 的KeyListener具有全局范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆