如何在Field子类中检测“删除”键?

时间:2021-12-13 07:17:08

I'm trying to detect and override the Delete key on the Blackberry keyboard.

我正在尝试检测并覆盖Blackberry键盘上的Delete键。

For some reason, it never makes it inside my case statement as when it hits that point:

出于某种原因,它永远不会在我的case语句中,因为它遇到了这一点:

Keypad.key(keycode) == 8
Keypad.KEY_DELETE == 127

What's my error?

我的错误是什么?

public class MyField extends ListField implements KeyListener {
// ...
/** Implementation of KeyListener.keyDown */
public boolean keyDown(int keycode, int time) {
    boolean retval = false;
    switch (Keypad.key(keycode)) {
    /* DELETE - Delete the timer */
    case Keypad.KEY_DELETE:
        if (Keypad.status(keycode) == KeyListener.STATUS_SHIFT) {
            _myDeleteCmd.run();
            retval = true;
        }
        break;

    default:
        retval = super.keyDown(keycode, time);
    }
    return retval;
}

1 个解决方案

#1


It's likely that the key event is being consumed by another KeyListener.keyDown function before it is able to reach this Field. You can easily test this by setting a break point within your keyDown() implementation to make sure that the application reaches this point.

在能够到达此字段之前,其他KeyListener.keyDown函数可能正在使用该键事件。您可以通过在keyDown()实现中设置断点来轻松地对此进行测试,以确保应用程序达到此点。

To consume a key event a KeyListener function just needs to return true. Make sure you aren't returning true by default for any other keyDown implementations to ensure that each implementation only consumes the keys that it uses.

要使用键事件,KeyListener函数只需要返回true。默认情况下,确保您没有为任何其他keyDown实现返回true,以确保每个实现仅消耗它使用的键。

#1


It's likely that the key event is being consumed by another KeyListener.keyDown function before it is able to reach this Field. You can easily test this by setting a break point within your keyDown() implementation to make sure that the application reaches this point.

在能够到达此字段之前,其他KeyListener.keyDown函数可能正在使用该键事件。您可以通过在keyDown()实现中设置断点来轻松地对此进行测试,以确保应用程序达到此点。

To consume a key event a KeyListener function just needs to return true. Make sure you aren't returning true by default for any other keyDown implementations to ensure that each implementation only consumes the keys that it uses.

要使用键事件,KeyListener函数只需要返回true。默认情况下,确保您没有为任何其他keyDown实现返回true,以确保每个实现仅消耗它使用的键。