Question

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

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

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;
}
Was it helpful?

Solution

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.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top