`
jacky-zhang
  • 浏览: 316776 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

Different platform, different keycodes

    博客分类:
  • j2me
阅读更多
package opusmicro.keycode.test;

//import game.MainCanvas;

import javax.microedition.lcdui.Canvas;

/**
 * Class redefines codes of mobile phone to our constant values.
 * Class can give to developers following information:
 * <ul>
 * <li/><i>defined platform name</i><br>
 * In case if device vendor not defined we'll recieve <code>PLATFORM_NOT_DEFINED</code> like platform name.
 * Same in this case keyCodes will be setted like for Nokia and SE. It's done for work on emulators,
 * because on some of them it's impossible to define platform name.
 * <li/><i>adopted to our constants key code value</i>
 * <li/><i>for test returns defined real code of left softkey</i>
 * </ul>
 */
public final class KeyCodeAdapter {

    /**
     * instance on this class
     */
    private static final KeyCodeAdapter instance = new KeyCodeAdapter();
    /**
     * canvas used for definig codes
     */
    private final Canvas adaptorCanvas;
    /**
     * constants for platforms  names
     */
    public static final String PLATFORM_MOTOROLA = "motorola";
    public static final String PLATFORM_NOKIA = "nokia";
    public static final String PLATFORM_SONY_ERICSSON = "SE";
    public static final String PLATFORM_SIEMENS = "siemens";
    public static final String PLATFORM_SAMSUNG = "samsung";
    public static final String PLATFORM_LG = "LG";
    public static final String PLATFORM_NOT_DEFINED = "NA";
    /**
     * constants for keycodes
     */
    public static final int SOFT_KEY_LEFT = -201;
    public static final int SOFT_KEY_RIGHT = -202;
    public static final int SOFT_KEY_MIDDLE_INTERNET = -203;
    /**
     * this key is present on Nokia s60
     */
    public static final int PENCIL_KEY = -207;
    public static final int DELETE_KEY = -204;
    public static final int BACK_KEY = -205;
    //    public static final int SEND_KEY = -206; //constant will be used in future for green key start dialling
    public static final int KEY_1 = 201;
    public static final int KEY_2 = 202;
    public static final int KEY_3 = 203;
    public static final int KEY_4 = 204;
    public static final int KEY_5 = 205;
    public static final int KEY_6 = 206;
    public static final int KEY_7 = 207;
    public static final int KEY_8 = 208;
    public static final int KEY_9 = 209;
    public static final int KEY_0 = 200;
    public static final int KEY__POUND = 211;
    public static final int KEY__STAR = 212;
    /**
     * KEYS on JOISTICK
     */
    public static final int UP_KEY = 221;
    public static final int DOWN_KEY = 222;
    public static final int LEFT_KEY = 223;
    public static final int RIGHT_KEY = 224;
    public static final int CENTER_KEY = 225;

    public static final int NOT_DEFINED_KEY = 254;

    /**
     * current platform name
     */
    private final String PLATFORM_NAME;
    /**
     * current platform codeofSoftkey
     */
    private final int SOFTKEY_LEFT;
    private final int SOFTKEY_RIGHT;
    private final int SOFTKEY_MIDDLE_INTERNET;
    private final int SOFTKEY_DELETE;
    private final int SOFTKEY_BACK;

    /**
     * standart values for softkeys of different platforms
     * used only in predefining
     */
    private static final int SOFT_KEY_LEFT_SE = -6;
    private static final int SOFT_KEY_RIGHT_SE = -7;
    private static final int DELETE_KEY_SE = -8;
    private static final int INTERNET_KEY_SE = -10;
    private static final int BACK_KEY_SE = -11;
    private static final int SOFT_KEY_LEFT_SAMSUNG = -6;
    private static final int SOFT_KEY_RIGHT_SAMSUNG = -7;
    private static final int DELETE_KEY_SAMSUNG = -8;
    private static final int SOFT_KEY_LEFT_SIEMENS = -1;
    private static final int SOFT_KEY_RIGHT_SIEMENS = -4;
    private static final int SOFT_KEY_LEFT_NOKIA = -6;
    private static final int SOFT_KEY_RIGHT_NOKIA = -7;
    private static final int DELETE_KEY_NOKIA = -8;
    private static final int PENCIL_KEY_NOKIA = -50;
    private static final int SOFT_KEY_LEFT_MOTOROLA = -21;
    private static final int SOFT_KEY_RIGHT_MOTOROLA = -22;
    private static final int SOFT_KEY_LEFT_MOTOROLA2 = -20;
    private static final int SOFT_KEY_LEFT_MOTOROLA1 = 21;
    private static final int SOFT_KEY_RIGHT_MOTOROLA1 = 22;
    private static final int SOFT_KEY_MIDLE_MOTOROLA = -23;
    private static final int SOFT_KEY_MIDLE_NOKIA = -5;

    private static final String SOFT_WORD = "SOFT";

    /**
     * constructor.
     * here is predefining of spesial keys and platform made
     */
    private KeyCodeAdapter() {
        adaptorCanvas = MainCanvas.getInstance();
        PLATFORM_NAME = getPlatform();
        SOFTKEY_LEFT = getLeftSoftkeyCode();
        SOFTKEY_RIGHT = getRightSoftkeyCode();
        SOFTKEY_MIDDLE_INTERNET = getMidleORInternetSoftkeyCode();
        SOFTKEY_DELETE = getDeleteKeyCode();
        SOFTKEY_BACK = getBackKeyCode();
    }

    /**
     * return platform keycode of left softkey
     * if it's defined
     * default value -6
     *
     * @return SOFTKEY_LEFT
     */
    public int getPlatformSoftkeyLeftCode() {
        return SOFTKEY_LEFT;
    }

    /**
     * Returns mobile phone platform
     *
     * @return name mobile phone platform
     */
    private String getPlatform() {
        // detecting NOKIA or SonyEricsson
        try {
            final String currentPlatform = System.getProperty("microedition.platform");
            if (currentPlatform.indexOf("Nokia") != -1) {
                return PLATFORM_NOKIA;
            } else if (currentPlatform.indexOf("SonyEricsson") != -1) {
                return PLATFORM_SONY_ERICSSON;
            }
        } catch (Throwable ex) {
        }
        // detecting SAMSUNG
        try {
            Class.forName("com.samsung.util.Vibration");
            return PLATFORM_SAMSUNG;
        } catch (Throwable ex) {
        }
        // detecting MOTOROLA
        try {
            Class.forName("com.motorola.multimedia.Vibrator");
            return PLATFORM_MOTOROLA;
        } catch (Throwable ex) {
            try {
                Class.forName("com.motorola.graphics.j3d.Effect3D");
                return PLATFORM_MOTOROLA;
            } catch (Throwable ex2) {
                try {
                    Class.forName("com.motorola.multimedia.Lighting");
                    return PLATFORM_MOTOROLA;
                } catch (Throwable ex3) {
                    try {
                        Class.forName("com.motorola.multimedia.FunLight");
                        return PLATFORM_MOTOROLA;
                    } catch (Throwable ex4) {
                    }
                }
            }
        }
        try {
            if (adaptorCanvas.getKeyName(SOFT_KEY_LEFT_MOTOROLA).toUpperCase().indexOf(SOFT_WORD) > -1) {
                return PLATFORM_MOTOROLA;
            }
        } catch (Throwable e) {
            try {
                if (adaptorCanvas.getKeyName(SOFT_KEY_LEFT_MOTOROLA1).toUpperCase().indexOf(SOFT_WORD) > -1) {
                    return PLATFORM_MOTOROLA;
                }
            } catch (Throwable e1) {
                try {
                    if (adaptorCanvas.getKeyName(SOFT_KEY_LEFT_MOTOROLA2).toUpperCase().indexOf(SOFT_WORD) > -1) {
                        return PLATFORM_MOTOROLA;
                    }
                } catch (Throwable e2) {
                }
            }
        }
        // detecting SIEMENS
        try {
            Class.forName("com.siemens.mp.io.File");
            return PLATFORM_SIEMENS;
        } catch (Throwable ex) {
        }
        // detecting LG
        try {
            Class.forName("mmpp.media.MediaPlayer");
            return PLATFORM_LG;
        } catch (Throwable ex) {
            try {
                Class.forName("mmpp.phone.Phone");
                return PLATFORM_LG;
            } catch (Throwable ex1) {
                try {
                    Class.forName("mmpp.lang.MathFP");
                    return PLATFORM_LG;
                } catch (Throwable ex2) {
                    try {
                        Class.forName("mmpp.media.BackLight");
                        return PLATFORM_LG;
                    } catch (Throwable ex3) {
                    }
                }
            }
        }
        return PLATFORM_NOT_DEFINED;
    }

    /**
     * define real left soft key code by platform
     *
     * @return code
     */
    private int getLeftSoftkeyCode() {
        int keyCode = 0;
        try {
            if (PLATFORM_NAME.equals(PLATFORM_MOTOROLA)) {
                String softkeyLeftMoto = "";
                try {
                    softkeyLeftMoto = adaptorCanvas.getKeyName(SOFT_KEY_LEFT_MOTOROLA).toUpperCase();
                } catch (IllegalArgumentException ilae) {
//                    ilae.printStackTrace();
                }
                String softkeyLeftMoto1 = "";
                try {
                    softkeyLeftMoto1 = adaptorCanvas.getKeyName(SOFT_KEY_LEFT_MOTOROLA1).toUpperCase();
                } catch (IllegalArgumentException ilae) {
//                    ilae.printStackTrace();
                }
                String softkeyLeftMoto2 = "";
                try {
                    softkeyLeftMoto2 = adaptorCanvas.getKeyName(SOFT_KEY_LEFT_MOTOROLA2).toUpperCase();
                } catch (IllegalArgumentException ilae) {
//                    ilae.printStackTrace();
                }
                if (softkeyLeftMoto.indexOf(SOFT_WORD) >= 0 && softkeyLeftMoto.indexOf("1") >= 0) {
                    return SOFT_KEY_LEFT_MOTOROLA;
                } else if (softkeyLeftMoto1.indexOf(SOFT_WORD) >= 0 && softkeyLeftMoto1.indexOf("1") >= 0) {
                    return SOFT_KEY_LEFT_MOTOROLA1;
                } else if (softkeyLeftMoto2.indexOf(SOFT_WORD) >= 0 && softkeyLeftMoto2.indexOf("1") >= 0) {
                    return SOFT_KEY_LEFT_MOTOROLA2;
                } else if (softkeyLeftMoto.indexOf(SOFT_WORD) >= 0 && softkeyLeftMoto.indexOf("LEFT") >= 0) {
                    return SOFT_KEY_LEFT_MOTOROLA;
                } else if (softkeyLeftMoto1.indexOf(SOFT_WORD) >= 0 && softkeyLeftMoto1.indexOf("LEFT") >= 0) {
                    return SOFT_KEY_LEFT_MOTOROLA1;
                } else if (softkeyLeftMoto2.indexOf(SOFT_WORD) >= 0 && softkeyLeftMoto2.indexOf("LEFT") >= 0) {
                    return SOFT_KEY_LEFT_MOTOROLA2;
                }

            } else if (PLATFORM_NAME.equals(PLATFORM_NOKIA)) {
                return SOFT_KEY_LEFT_NOKIA;
            } else if (PLATFORM_NAME.equals(PLATFORM_SAMSUNG)) {
//                String leftkeySamsungName = adaptorCanvas.getKeyName(SOFT_KEY_LEFT_SAMSUNG).toUpperCase();
//                if (leftkeySamsungName.indexOf(SOFT_WORD) >= 0) {
//                    if (leftkeySamsungName.indexOf("1") >= 0) {
                return SOFT_KEY_LEFT_SAMSUNG;
//                    } else if (leftkeySamsungName.indexOf("LEFT") >= 0) {
//                        return SOFT_KEY_LEFT_SAMSUNG;
//                    }
//                }
            } else if (PLATFORM_NAME.equals(PLATFORM_SIEMENS)) {
                String leftKeySiemensName = adaptorCanvas.getKeyName(SOFT_KEY_LEFT_SIEMENS).toUpperCase();
                if (leftKeySiemensName.indexOf(SOFT_WORD) >= 0) {
                    if (leftKeySiemensName.indexOf("1") >= 0) {
                        return SOFT_KEY_LEFT_SIEMENS;
                    } else if (leftKeySiemensName.indexOf("LEFT") >= 0) {
                        return SOFT_KEY_LEFT_SIEMENS;
                    }
                }
            } else if (PLATFORM_NAME.equals(PLATFORM_SONY_ERICSSON)) {
                return SOFT_KEY_LEFT_SE;
            } else if (PLATFORM_NAME.equals(PLATFORM_NOT_DEFINED)) {
                //
                for (int i = -125; i <= 125; i++) {
                    if (i == 0) {
                        i++;
                    }
//                    System.out.println(getKeyName(i).toUpperCase());
                    final String s = adaptorCanvas.getKeyName(i).toUpperCase();
                    if (s.indexOf(SOFT_WORD) >= 0) {
                        if (s.indexOf("1") >= 0) {
                            keyCode = i;
                            break;
                        }
                        if (s.indexOf("LEFT") >= 0) {
                            keyCode = i;
                            break;
                        }
                    }
                }
            }
            if (keyCode == 0) {
                //#if emulator
                return SOFT_KEY_LEFT_NOKIA;
                //#endif
            }
        } catch (Throwable iaEx) {
            //#if emulator
            return SOFT_KEY_LEFT_NOKIA;
            //#endif
        }
        return keyCode;
    }

    /**
     * define real right soft key code for current platform
     *
     * @return code
     */
    private int getRightSoftkeyCode() {
        int keyCode = 0;
        try {
            if (PLATFORM_NAME.equals(PLATFORM_MOTOROLA)) {

                String rightSoftMoto1 = "";
                try {
                    rightSoftMoto1 = adaptorCanvas.getKeyName(SOFT_KEY_LEFT_MOTOROLA1).toUpperCase();
                } catch (IllegalArgumentException ilae) {
//                    ilae.printStackTrace();
                }
                String rightSoftMoto = "";
                try {
                    rightSoftMoto = adaptorCanvas.getKeyName(SOFT_KEY_RIGHT_MOTOROLA).toUpperCase();
                } catch (IllegalArgumentException ilae) {
//                    ilae.printStackTrace();
                }
                String rightSoftMoto2 = "";
                try {
                    rightSoftMoto2 = adaptorCanvas.getKeyName(SOFT_KEY_RIGHT_MOTOROLA1).toUpperCase();
                } catch (IllegalArgumentException ilae) {
//                    ilae.printStackTrace();
                }
                if (rightSoftMoto.indexOf(SOFT_WORD) >= 0 && rightSoftMoto.indexOf("2") >= 0) {
                    return SOFT_KEY_RIGHT_MOTOROLA;
                } else if (rightSoftMoto1.indexOf(SOFT_WORD) >= 0 && rightSoftMoto1.indexOf("2") >= 0) {
                    return SOFT_KEY_RIGHT_MOTOROLA;
                } else if (rightSoftMoto2.indexOf(SOFT_WORD) >= 0 && rightSoftMoto2.indexOf("2") >= 0) {
                    return SOFT_KEY_RIGHT_MOTOROLA1;
                } else if (rightSoftMoto.indexOf(SOFT_WORD) >= 0 && rightSoftMoto.indexOf("RIGHT") >= 0) {
                    return SOFT_KEY_LEFT_MOTOROLA;
                } else if (rightSoftMoto1.indexOf(SOFT_WORD) >= 0 && rightSoftMoto1.indexOf("RIGHT") >= 0) {
                    return SOFT_KEY_RIGHT_MOTOROLA1;
                } else if (rightSoftMoto2.indexOf(SOFT_WORD) >= 0 && rightSoftMoto2.indexOf("RIGHT") >= 0) {
                    return SOFT_KEY_RIGHT_MOTOROLA;
                }

            } else if (PLATFORM_NAME.equals(PLATFORM_NOKIA)) {
                return SOFT_KEY_RIGHT_NOKIA;
            } else if (PLATFORM_NAME.equals(PLATFORM_SAMSUNG)) {
//                String rightSoftSamsung = adaptorCanvas.getKeyName(SOFT_KEY_RIGHT_SAMSUNG).toUpperCase();
//                if (rightSoftSamsung.indexOf(SOFT_WORD) >= 0) {
//                    if (rightSoftSamsung.indexOf("2") >= 0) {
                return SOFT_KEY_RIGHT_SAMSUNG;
//                    } else if (rightSoftSamsung.indexOf("RIGHT") >= 0) {
//                        return SOFT_KEY_RIGHT_SAMSUNG;
//                    }
//                }
            } else if (PLATFORM_NAME.equals(PLATFORM_SIEMENS)) {
                String rightSoftSiemens = adaptorCanvas.getKeyName(SOFT_KEY_RIGHT_SIEMENS).toUpperCase();
                if (rightSoftSiemens.indexOf(SOFT_WORD) >= 0) {
                    if (rightSoftSiemens.indexOf("4") >= 0) {
                        return SOFT_KEY_RIGHT_SIEMENS;
                    } else if (rightSoftSiemens.indexOf("RIGHT") >= 0) {
                        return SOFT_KEY_RIGHT_SIEMENS;
                    }
                }
            } else if (PLATFORM_NAME.equals(PLATFORM_SONY_ERICSSON)) {
                return SOFT_KEY_RIGHT_SE;
            } else if (PLATFORM_NAME.equals(PLATFORM_NOT_DEFINED)) {
                for (int i = -125; i <= 125; i++) {
                    if (i == 0) {
                        i++;
                    }
                    String keyName = adaptorCanvas.getKeyName(i).toUpperCase();
                    if (keyName.indexOf(SOFT_WORD) >= 0) {
                        if (keyName.indexOf("2") >= 0) {
                            keyCode = i;
                            break;
                        } else if (keyName.indexOf("4") >= 0) {
                            keyCode = i;
                            break;
                        } else if (keyName.indexOf("RIGHT") >= 0) {
                            keyCode = i;
                            break;
                        }
                    }
                }
            }
        } catch (Throwable iaEx) {
            //#if emulator
            return SOFT_KEY_RIGHT_NOKIA;
            //#endif
        }
        return keyCode;
    }

    /**
     * define real middle soft key code for current platform
     *
     * @return code
     */
    private int getMidleORInternetSoftkeyCode() {
        try {
            if (PLATFORM_NAME.equals(PLATFORM_MOTOROLA)) {
                if (adaptorCanvas.getKeyName(SOFT_KEY_MIDLE_MOTOROLA).toUpperCase().indexOf("SOFT") >= 0) {
                    return SOFT_KEY_MIDLE_MOTOROLA;
                }
            } else if (PLATFORM_NAME.equals(PLATFORM_NOKIA)) {
                if (adaptorCanvas.getKeyName(SOFT_KEY_MIDLE_NOKIA).toUpperCase().indexOf("SOFT") >= 0) {
                    return SOFT_KEY_MIDLE_NOKIA;
                }
            } else if (PLATFORM_NAME.equals(PLATFORM_SAMSUNG)) {
            } else if (PLATFORM_NAME.equals(PLATFORM_SIEMENS)) {
            } else if (PLATFORM_NAME.equals(PLATFORM_SONY_ERICSSON)) {
                return INTERNET_KEY_SE;
            }
        } catch (Throwable e) {
        }
        return 0;
    }

    /**
     * define real key's C or DELETE code for current platform
     *
     * @return code
     */
    private int getDeleteKeyCode() {
        try {
            if (PLATFORM_NAME.equals(PLATFORM_MOTOROLA)) {

            } else if (PLATFORM_NAME.equals(PLATFORM_NOKIA)) {
                if (adaptorCanvas.getKeyName(DELETE_KEY_SE).toUpperCase().indexOf("CLEAR") >= 0) {
                    return DELETE_KEY_NOKIA;
                } else {
                    return DELETE_KEY_NOKIA;
                }
            } else if (PLATFORM_NAME.equals(PLATFORM_SAMSUNG)) {
                if (adaptorCanvas.getKeyName(DELETE_KEY_SAMSUNG).toUpperCase().indexOf("CLEAR") >= 0) {
                    return DELETE_KEY_SAMSUNG;
                }
            } else if (PLATFORM_NAME.equals(PLATFORM_SIEMENS)) {
            } else if (PLATFORM_NAME.equals(PLATFORM_SONY_ERICSSON)) {
                if (adaptorCanvas.getKeyName(DELETE_KEY_SE).toUpperCase().indexOf("CLEAR") >= 0) {
                    return DELETE_KEY_SE;
                } else if (adaptorCanvas.getKeyName(DELETE_KEY_SE).toUpperCase().indexOf("C") >= 0) {
                    return DELETE_KEY_SE;
                } else {
                    return DELETE_KEY_SE;
                }
            }
        } catch (Throwable e) {
            return DELETE_KEY_SE;
        }
        return 0;
    }


    /**
     * define real key's BACK code for current platform
     *
     * @return code
     */
    private int getBackKeyCode() {
        try {
            if (PLATFORM_NAME.equals(PLATFORM_MOTOROLA)) {

            } else if (PLATFORM_NAME.equals(PLATFORM_NOKIA)) {

            } else if (PLATFORM_NAME.equals(PLATFORM_SAMSUNG)) {
            } else if (PLATFORM_NAME.equals(PLATFORM_SIEMENS)) {
            } else if (PLATFORM_NAME.equals(PLATFORM_SONY_ERICSSON)) {
                return BACK_KEY_SE;
            }
        } catch (Throwable e) {
        }
        return 0;
    }

    /**
     * name of curent platform
     *
     * @return PLATFORM_NAME
     */
    public String getPlatformName() {
        return PLATFORM_NAME;
    }

    /**
     * Used to adopt key kode to predefined constances, which are platform independent.
     * <p/>
     * You can use this method in any kind of canvas, but better at first time to call
     * <code>getInstance()</code> method at the beginning of midlet work, because initialisation takes time.
     * <p/>
     * Best variant for usage is calling <code>adoptKeyCode()</code> to use <code>keyPressed()</code> method in Canvas:
     * <pre>
     * protected void keyPressed(int keyCode) {
     *     keyCode = KeyCodeAdapter.getInstance().adoptKeyCode(keyCode);
     * }
     * </pre>
     * and then you can use it:
     * <pre>
     * switch (keyCode) {
     *   case KeyCodeAdapter.UP_KEY:
     *     break;
     *   case KeyCodeAdapter.SOFT_KEY_LEFT:
     *     break;
     * }</pre>
     * or send this code to any other clesses.
     *
     * @param keycode This code is sent by platform to canvas and redirected here
     * @return this keycode is equal to one of our constants declared in this class
     */
    public int adoptKeyCode(int keycode) {
        switch (keycode) {
            case Canvas.KEY_NUM0:
                return KEY_0;
            case Canvas.KEY_NUM1:
                return KEY_1;
            case Canvas.KEY_NUM2:
                return KEY_2;
            case Canvas.KEY_NUM3:
                return KEY_3;
            case Canvas.KEY_NUM4:
                return KEY_4;
            case Canvas.KEY_NUM5:
                return KEY_5;
            case Canvas.KEY_NUM6:
                return KEY_6;
            case Canvas.KEY_NUM7:
                return KEY_7;
            case Canvas.KEY_NUM8:
                return KEY_8;
            case Canvas.KEY_NUM9:
                return KEY_9;
            case Canvas.KEY_STAR:
                return KEY__STAR;
            case Canvas.KEY_POUND:
                return KEY__POUND;
            default:
                if (keycode == SOFTKEY_LEFT) {
                    return SOFT_KEY_LEFT;
                } else if (keycode == SOFTKEY_RIGHT) {
                    return SOFT_KEY_RIGHT;
                } else if (keycode == SOFTKEY_DELETE) {
                    return DELETE_KEY;
                } else if (keycode == SOFTKEY_BACK) {
                    return BACK_KEY;
                } else if (keycode == SOFTKEY_MIDDLE_INTERNET) {
                    return SOFT_KEY_MIDDLE_INTERNET;
                } else if (keycode == PENCIL_KEY_NOKIA) {
                    return PENCIL_KEY;
                } else {
                    try {
                        final int gameAction;
                        gameAction = adaptorCanvas.getGameAction(keycode);
                        if (gameAction == Canvas.UP) {
                            return UP_KEY;
                        } else if (gameAction == Canvas.DOWN) {
                            return DOWN_KEY;
                        } else if (gameAction == Canvas.LEFT) {
                            return LEFT_KEY;
                        } else if (gameAction == Canvas.RIGHT) {
                            return RIGHT_KEY;
                        } else if (gameAction == Canvas.FIRE) {
                            return CENTER_KEY;
                        }
                    } catch (IllegalArgumentException e) {
//                    e.printStackTrace();
                    }
                }
                break;
        }
        //#if debug
        //# return keycode;
        //#else
        return NOT_DEFINED_KEY;
        //#endif
    }

    /**
     * return instance of class
     *
     * @return instance
     */
    public static KeyCodeAdapter getInstance() {
        return instance;
    }
}


After actions described above it is enough to transform provided by Canvas native key-codes to our internal. This can be made by simple calling the method adoptKeyCode(), like following:
protected void keyPressed(int keyCode) {
        int internalKeyCode = KeyCodeAdapter.getInstance().adoptKeyCode(keyCode);
        switch (keyCode) {
            case KeyCodeAdapter.SOFT_KEY_LEFT:
                // some processing
                break;
            case KeyCodeAdapter.BACK_KEY:
                // some processing
                break;
            default:
        }
        ...
    }
分享到:
评论

相关推荐

    day11-Event Keycodes(事件键码)

    在编程领域,尤其是在Web开发中,理解和使用Event Keycodes对于创建交互式的用户界面至关重要。Event Keycodes是JavaScript中用于识别键盘按键的一种方式,它是一个整数值,代表了键盘上每个键的唯一标识。今天我们...

    atom-keycodes:轻松访问javascript keyCodes

    《深入理解JavaScript键码库atom-keycodes》 在JavaScript编程中,处理键盘事件时经常会遇到一个挑战:如何正确地识别并处理用户按下键盘上的不同按键。为此,开发者们开发了一个名为"atom-keycodes"的库,它为...

    DSP.rar_Different_fft codes in matlab_upsampling

    Different DSP related source codes pertaining to FFT,Convolution,filtering,concatenation of signals in different frequencies,sampling including upsampling & downsampling

    Virtual Key Codes for vc programming

    在进行VC编程时,了解和掌握虚拟键码(Virtual Key Codes)是非常重要的,尤其是在需要处理键盘输入的应用程序开发中。虚拟键码是Windows系统用来表示特定键盘按键的标准代码,它们被广泛应用于各种与键盘交互相关的...

    Codes_python_Different_

    在"Codes_python_Different_"这个压缩包中,我们很显然会发现一系列与Python编程相关的源代码文件。这些代码可能是为了解决各种不同的问题而编写的,正如描述中提到的那样。Python是一种广泛使用的高级编程语言,以...

    js中键盘对应的key值

    - keycodes 33 到 40 对应页面导航键:Page Up(Prior)、Page Down(Next)、End、Home、左箭头(Left)、上箭头(Up)、右箭头(Right)、下箭头(Down)。 - keycodes 41 对应 Select 键。 - keycodes 42 对应 ...

    JS Keycodes-crx插件

    语言:English ...JS Keycodes是一个简单的chrome扩展程序,可帮助JavaScript开发人员轻松访问这些烦人的事件键码。 该工具旨在作为直观设计的快速参考。 说明很简单,运行扩展名,然后输入要查看其键码的字符。

    vhdl.rar_Different_VHDL PROJECTS CODES

    本压缩包“vhdl.rar_Different_VHDL_PROJECTS_CODES”包含了多个VHDL源代码项目,这些项目覆盖了不同的数字电路设计实例,下面将详细解析这些文件中的知识点。 1. **bin_to_7seg.vhd**:这是一个二进制到七段显示...

    event_keycodes

    在IT行业中,`event_keycodes`是一个非常关键的概念,特别是在处理键盘事件时。它涉及到JavaScript、HTML、CSS以及Web开发中的交互设计。标题"event_keycodes"直指这个主题,而描述同样简单明了,没有提供额外信息。...

    different-pliot-length-matlab-codes.rar_Different_导频

    不同导频长度的MATLAB的仿真程序,包含5个代码附件

    event-keycodes

    这个标题“event-keycodes”暗示了我们要讨论的是键盘事件与它们对应的键码值,这些键码值在处理键盘输入时非常关键。 HTML(超文本标记语言)是构建网页的基础,它允许我们在网页上添加文本、图像、链接等多种元素...

    Eclipse Rich Client Platform源码下载

    本书 , Coding, and Packaging Java™ Applications&gt;&gt;是eclipse官方rcp的推荐教材之一。书中由浅入深地集合rcp框架实现了一个聊天工具的开发。教材是英文版的。 源码以eclipse插件的方式提供,按eclipse插件方式配置...

    userthre.rar_Different_cdma pn_cdma pn matlab

    cdma simuklation with differetn users , pn sequences and their characterstics with new codes and also how to simulate it in matlab with different cdma codes for different no of users in the system

    node-keycodes-enum:简单的键码枚举,使代码更具可读性

    在JavaScript编程中,`node-keycodes-enum` 是一个实用的库,它的主要目标是提供一个简洁、易读的方式来处理键盘事件中的键码。键码是JavaScript中用于识别用户按下键盘上哪个键的整数值。通常,这些键码是通过它们...

    隐藏的功能 Skyworth TV 43G6 9R61 KEYCODES

    Hidden Functions 隐藏的功能 of Skyworth TV 43G6 9R61 Called from ADB

    Javascript Key Codes-crx插件

    JavaScript Key Codes是一款针对JavaScript开发者的Chrome扩展程序,它主要提供了便捷的方式来查看和了解JavaScript中的键盘事件对应的键码。在Web开发中,特别是涉及到用户输入交互时,了解键盘事件及其键码是非常...

    keycodes:名称到关键代码的映射

    安装 $ npm install @nichoth/keycodes用 // everythingvar codes = require ( '@nichoth/keycodes' ) ;var ENTER = codes . enter ;// one thingvar ENTER = require ( '@nichoth/keycodes/enter' ) ;

    Key Codes:显示您键入的密钥及其 ASCII 代码编号的快速工具。-开源

    如果它是一个修饰键,输入一些东西并按住它,你会看到你输入的键和那个字符的 ASCII 编码号。

Global site tag (gtag.js) - Google Analytics