开发者

Is it possible to get the keycode not tha Native keycode in GWT?

开发者 https://www.devze.com 2023-02-28 14:00 出处:网络
I want to get the keycode(String) not the Native keycode in GWT keyUP event handler I tried but I only can get the native keycode which returns the ASCII of the key.Is it possible to get the string of

I want to get the keycode(String) not the Native keycode in GWT keyUP event handler I tried but I only can get the native keycode which returns the ASCII of the key. Is it possible to get the string of the keycode?

I recognize that GWT does not use some java JREs they only use the JREs they found it useful:(...really disappointed. I have to write a donkey work code in order to get functions that do the same work as the lost JREs from GWT and here is my code to solve that issue...which i feel of shame to write such code but GWT made me have no other choice if any one can help please!

if((int)event.getNativeKeyCode()==13)
            {
                code="Enter";
            }
            if((int)event.getNativeKeyCode()==65)
            {
                code="A";
            }
            if((int)event.getNativeKeyCode()==66)
            {
                code="B";
            }
            if((int)event.getNativeKeyCode()==67)
            {
                code="C";
            }
            if((int)event.getNativeKeyCode()==68)
            {
                code="D";
            }
            if((int)event.getNativeKeyCode()==69)
            {
                code="E";
            }
            if((int)event.getNativeKeyCode()==70)
            {
                code="F";
            }
            if((int)event.getNativeKeyCode()==71)
            {
                code="G";
            }
            if((int)event.getNativeKeyCode()==72)
            {
                code="H";
            }
            if((int)event.getNativeKeyCode()==73)
            {
                code="I";
            }
            if((int)event.getNativeKeyCode()==74)
            {
                code="J";
            }
            if((int)event.getNativeKeyCode()==75)
            {
                code="K";
            }
            if((int)event.getNativeKeyCode()==76)
            {
                code="L";
            }
            if((int)event.getNativeKeyCode()==77)
            {
                code="M";
            }
            if((int)event.getNativeKeyCode()==78)
            {
                code="N";
            }
            if((int)event.getNativeKeyCode()==79)
            {
                code="O";
            }
            if((int)event.getNativeKeyCode()==80)
            {
                code="P";
            }
            if((int)event.getNativeKeyCode()==81)
            {
                code="Q";
            }
            if((int)event.getNativeKeyCode()==82)
            {
                code="R";
            }
            if((int)event.getNativeKeyCode()==83)
            {
                code="S";
            }
            if((int)event.getNativeKeyCode()==84)
            {
                code="T";
            }
            if((int)event.getNativeKeyCode()==85)
            {
                code="U";
            }
            if((int)event.getNativeKeyCode()==86)
            {
                code="V";
            }
            if((int)event.getNativeKeyCode()==87)
            {
                code="W";
            }
            if((int)event.getNativeKeyCode()==88)
            {
                code="X";
            }
            if((int)event.getNativeKeyCode()==89)
            {
                code="Y";
            }
            if((int)event.getNativeKeyCode()==90)
            {
                code="Z";
            }
            if((int)event.getNativeKeyCode()==48)
            {
                code="0";
            }
            if((int)event.getNativeKeyCode()==49)
            {
                code="1";
            }
            if((int)event.getNativeKeyCode()==50)
            {
                code="2";
            }
            if((int)event.getNativeKeyCode()==51)
            {
                code="3";
            }
            if((int)event.getNativeKeyCode()==52)
            {
                code="4";
            }
            if((int)event.getNativeKeyCode()==53)
            {
                code="5";
            }
            if((int)event.getNativeKeyCode()==54)
            {
                code="6";
            }
            if((int)event.getNativeKeyCode()==55)
            {
                code="7";
            }
            if((int)event.getNativeKeyCode()==56)
            {
                code="8";
            }
            if((int)event.getNativeKeyCode()==57)
            {
                code="9";
            }
            if((int)event.getNativeKeyCode()==96)
            {
                code="Numpad 0";
            }
          开发者_JS百科  if((int)event.getNativeKeyCode()==97)
            {
                code="Numpad_1";
            }
            if((int)event.getNativeKeyCode()==98)
            {
                code="Numpad_2";
            }
            if((int)event.getNativeKeyCode()==99)
            {
                code="Numpad_3";
            }
            if((int)event.getNativeKeyCode()==100)
            {
                code="Numpad_4";
            }
            if((int)event.getNativeKeyCode()==101)
            {
                code="Numpad_5";
            }
            if((int)event.getNativeKeyCode()==102)
            {
                code="Numpad_6";
            }
            if((int)event.getNativeKeyCode()==103)
            {
                code="Numpad_7";
            }
            if((int)event.getNativeKeyCode()==104)
            {
                code="Numpad_8";
            }
            if((int)event.getNativeKeyCode()==105)
            {
                code="Numpad_9";
            }
            if((int)event.getNativeKeyCode()==106)
            {
                code="Multiply";
            }
            if((int)event.getNativeKeyCode()==107)
            {
                code="Add";
            }
            if((int)event.getNativeKeyCode()==109)
            {
                code="Subtract";
            }
            if((int)event.getNativeKeyCode()==110)
            {
                code="Decimal";
            }
            if((int)event.getNativeKeyCode()==111)
            {
                code="Divide";
            }
            if((int)event.getNativeKeyCode()==8)
            {
                code="BackSpace";
            }
            if((int)event.getNativeKeyCode()==9)
            {
                code="Tab";
            }
            if((int)event.getNativeKeyCode()==16)
            {
                code="Shift";
            }
            if((int)event.getNativeKeyCode()==17)
            {
                code="Control";
            }
            if((int)event.getNativeKeyCode()==20)
            {
                code="Caps_Lock";
            }
            if((int)event.getNativeKeyCode()==27)
            {
                code="ESC";
            }
            if((int)event.getNativeKeyCode()==32)
            {
                code="Space";
            }
            if((int)event.getNativeKeyCode()==33)
            {
                code="Page_Up";
            }
            if((int)event.getNativeKeyCode()==34)
            {
                code="Page_Down";
            }
            if((int)event.getNativeKeyCode()==35)
            {
                code="End";
            }
            if((int)event.getNativeKeyCode()==36)
            {
                code="Home";
            }
            if((int)event.getNativeKeyCode()==37)
            {
                code="Left_Arrow";
            }
            if((int)event.getNativeKeyCode()==38)
            {
                code="Up_Arrow";
            }
            if((int)event.getNativeKeyCode()==39)
            {
                code="Right_Arrow";
            }
            if((int)event.getNativeKeyCode()==40)
            {
                code="Down_Arrow";
            }
            if((int)event.getNativeKeyCode()==45)
            {
                code="Insert";
            }
            if((int)event.getNativeKeyCode()==46)
            {
                code="Delete";
            }
            if((int)event.getNativeKeyCode()==144)
            {
                code="Num_Lock";
            }
            if((int)event.getNativeKeyCode()==145)
            {
                code="ScrLk";
            }
            if((int)event.getNativeKeyCode()==186)
            {
                code=";";
            }
            if((int)event.getNativeKeyCode()==187)
            {
                code="=";
            }
            if((int)event.getNativeKeyCode()==189)
            {
                code="-";
            }
            if((int)event.getNativeKeyCode()==191)
            {
                code="/";
            }
            if((int)event.getNativeKeyCode()==192)
            {
                code="`";
            }
            if((int)event.getNativeKeyCode()==219)
            {
                code="[";
            }

            if((int)event.getNativeKeyCode()==221)
            {
                code="]";
            }
            if((int)event.getNativeKeyCode()==222)
            {
                code="'";
            }
            if((int)event.getNativeKeyCode()==188)
            {
                code=",";
            }
            if((int)event.getNativeKeyCode()==190)
            {
                code=".";
            }
            if((int)event.getNativeKeyCode()==191)
            {
                code="/";
            }


See the Keycodes class. It provides constants you can use instead.

Example:

switch (event.getNativeKeyCode()) {
    case KeyCodes.ENTER: break;
    case KeyCodes.KEY_P: break;
}


Im not exactly ure what you mean but it might be simply that your using the wrong key event. If i recall on some browsers keydown or is it keypress deliver different things , one gives codes the other chars.


Basically, keydown/keyup events are for "keys" while keypress is for "printable chars". If you want "chars", then use a KeyPressHandler instead. Firefox will fire too many events (i.e. even for non-printable chars) but you can easily tell, as the charCode will then be 0.

Is there any reason you really want to do that in keyup?

0

精彩评论

暂无评论...
验证码 换一张
取 消