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
New Developer
phucnhfpt
Posts: 119
Registered: 10-23-2009

Get key value of ALT and SHIFT

I read the example in How To - Detect Alt and Shift key clicks. But after repair i have :

import net.rim.device.api.system.Characters;
import net.rim.device.api.system.KeyListener;
import net.rim.device.api.system.KeypadListener;
import net.rim.device.api.ui.Keypad;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.Screen;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.container.MainScreen;

class KeyHandlerScreen extends Screen 
{

                // Invoked when a key is pressed.
        protected boolean keyDown(int keycode, int time) 
        {        
                int key = Keypad.key(keycode); 
                int status = Keypad.status(keycode);
                if ((status & KeypadListener.STATUS_ALT) != 0) 
                {
                        Dialog.inform("Key(" + key + ")" + "Alt");

                } 
                else if ((status & KeypadListener.STATUS_SHIFT) != 0) 
                {
                        Dialog.inform("Key(" + key + ")" + "Shift");
                }
                return super.keyDown(keycode, time);
        }

        //      Invoked when a sequence of one or more key presses
        //      generates a character.
        protected boolean keyChar(char key, int status, int time) 
        {
                switch (key) 
                {
                        case (Characters.ESCAPE):
                    if ((status & KeypadListener.STATUS_ALT) != 0) 
                    {
                        Dialog.inform("Alt + ESC");
                    } 
                    else if ((status & KeypadListener.STATUS_SHIFT) != 0) 
                    { 
                        Dialog.inform("Alt + Shift");
                    }
                    return true;
                }
                return super.keyChar(key, status, time);
        }
        
        protected void sublayout(int width, int height) 
        {
                // TODO Auto-generated method stub
                
        }

}

 

 

But i don't know how to use it and create contrustor for it. Pls help?




Please use plain text.