Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Contributor
Luis_Pena_Nunez
Posts: 18
Registered: ‎08-23-2012
My Device: Blackberry 9990

how can i deactivate the Escape key

Hello i'm luis.

 

this is my code: 

 

public class openWWW extends MainScreen {
boolean aFlag;

public openWWW(boolean hd) {
BrowserSession browser = Browser.getDefaultSession();
Browser.getDefaultSession().displayPage(webPage);
}

protected boolean keyDown(int keycode, int time) {
if (Keypad.key(keycode) == Keypad.KEY_ESCAPE) {
return false;
}
return false;
}

public boolean onClose() {
return false;
}

private void error(final String message) {
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
Dialog.alert(message);
}
});
}
}

 


but when i press the escape button the app back to the previous Screen
 
what is the mistake?  

 

Developer
peter_strange
Posts: 19,610
Registered: ‎07-14-2008
My Device: Not Specified

Re: how can i deactivate the Escape key

Try overriding keyChar rather than keyDown.  Works for me. 

Developer
tklanilkumar
Posts: 206
Registered: ‎02-22-2011
My Device: BB TORCH & 9800

Re: how can i deactivate the Escape key

Hi,

To deactivate , I checked with your code its worked for me with keyDown itself.

Also try as peter suggested, and tell us what happend .

*****************************************************************************
* Give kudos when you like it
* Mark it as a solution if it fixes your issue
Developer
BrajeshSanodiya
Posts: 134
Registered: ‎08-03-2011
My Device: torch, Z10

Re: how can i deactivate the Escape key

Use this code for escape key.

 

protected boolean keyChar(char c, int status, int time) {
		try {
			if (c == Characters.ESCAPE) {
				synchronized (UiApplication.getEventLock()) {
					// action for escape key
				}
			}
		} catch (Exception ex) {
		}
		return super.keyChar(c, status, time);
	}

 

-----------------------------------------------------------------------
"Like" if you liked the post.
"Accept as Solution" if the post solves your question.
-----------------------------------------------------------------------
Developer
peter_strange
Posts: 19,610
Registered: ‎07-14-2008
My Device: Not Specified

Re: how can I deactivate the Escape key

Regarding the code provided by BrajeshSanodiya, because keyChar actually already runs on the Event Thread, there is no need to get the EventLock.  You can run UI updating code in your keyChar method without needing to do any of the tricks. 

 

In other words, the keyChar code provided could be simplified to:

 

protected boolean keyChar(char c, int status, int time) {
 try {
  if (c == Characters.ESCAPE) {
    // action for escape key
    return; // make sure super.keyChar is not invoked
  }
 } catch (Exception ex) {
 }
 return super.keyChar(c, status, time);
}