BlackBerry - 具有全局范围的KeyListener

Abs*_*Abs 5 key-events blackberry keylistener keylogger java-me

我是BlackBerry App开发的新手.我希望能够在BlackBerry(我的情况下为8900)打开时监听按键事件,并且在所有屏幕上都可以这样做吗?

如果是这样,那么有人能指引我朝着正确的方向前进.我已经看过Interface KeyListener了.

import net.rim.device.api.system.*;
Run Code Online (Sandbox Code Playgroud)

谢谢大家

Ali*_*Ali 6

实现keylistenerClass,如:

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

}
Run Code Online (Sandbox Code Playgroud)

然后在你的应用程序构造器中

public Application() {

    //Add the listener to the system for this application
    addKeyListener(new ShortcutHandler());
}
Run Code Online (Sandbox Code Playgroud)

当应用程序在后台时,我确认它正在工作.