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
Developer
Posts: 511
Registered: ‎05-31-2009
My Device: Not Specified

Unauthorized attempt to monitor keypresses error

Hi folks- does anyone know the way to authorize the use of a keylistener and avoid the error message 'Unauthorized attempt to monitor keypresses' on the Bold device? The code is below:

 

                            tkl = new TheKeyListener();
                            MonthlySpend.getApplication().addKeyListener(tkl);


public static class TheKeyListener implements KeyListener 

{
     public TheKeyListener()
     {
         System.out.println("\n\n\nAdded key listener.\n\n\n");
     }
    
     // Implement methods in the KeyListener interface for handling keyboard events:
     public boolean keyChar(char key, int status, int time)
     {
         return false;
     }
    
     public boolean keyDown(int keycode, int time)
     {
         System.out.println("Keycode is " + String.valueOf(keycode));
         MonthlySpend.getApplication().removeKeyListener(tkl);
       
         if (keycode == 1179648) // End button (red)
         {
            EventInjector.KeyCodeEvent simulateKey = new EventInjector.KeyCodeEvent(EventInjector.KeyCodeEvent.KEY_DOWN, Characters.ESCAPE, 0);   // (char)1769472
            simulateKey.post();
            simulateKey.post();   
            return true;
         }
         else
            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;
     }   
}

 

Developer
Posts: 984
Registered: ‎02-10-2009
My Device: Not Specified

Re: Unauthorized attempt to monitor keypresses error