views:

619

answers:

1

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;
}
+2  A: 

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.

Fostah
Been there, done that. Added the relevant values in the question. Hey, while we're at it, who gets first shot at the event? System -> Application -> Screen -> Manager -> Field?
MikeyB
Keypad.KEY_BACKSPACE = 8; That's the value you need to check against. I'm not sure the difference between the two, but they are often cased together.Not 100% percent on the order. I believe you are correct. The Application has an event dispatcher that dispatches events to the active screen, who then dispatches to the screen's Managers and Fields. However, I'm sure about ordering at that point. I would guess it would go through each Manager in the order they were added to the screen, and the same for each Manager's Fields.
Fostah
Ahh... BACKSPACE, not DELETE. Gotcha :) Thanks!
MikeyB