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. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Java Development

Reply
Developer
justindutoit
Posts: 394
Registered: ‎05-31-2009

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;
     }   
}

 

Please use plain text.
Developer
bikas
Posts: 984
Registered: ‎02-10-2009

Re: Unauthorized attempt to monitor keypresses error

Please use plain text.