是否可以在 GWT 中获取非本机键码的键码?

发布于 2024-11-03 05:10:02 字数 9015 浏览 1 评论 0原文

我想在我尝试过的 GWT keyUP 事件处理程序中获取键码(字符串)而不是本机键码,但我只能获取返回键的 ASCII 的本机键码。是否可以获取密钥代码的字符串?

我认识到 GWT 不使用某些 java JRE,他们只使用他们发现有用的 JRE:(...真的很失望。我必须编写一个驴工作代码,以便获得与丢失的 JRE 执行相同工作的函数GWT 这是我解决这个问题的代码...我对编写这样的代码感到羞耻,但 GWT 让我别无选择,如果有人可以帮忙的话!

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";
            }
            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="/";
            }

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";
            }
            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="/";
            }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

感情废物 2024-11-10 05:10:02

请参阅键码 类。它提供了您可以使用的常量。

例子:

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

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

Example:

switch (event.getNativeKeyCode()) {
    case KeyCodes.ENTER: break;
    case KeyCodes.KEY_P: break;
}
嘦怹 2024-11-10 05:10:02

我不太清楚你的意思,但可能只是你使用了错误的按键事件。如果我记得在某些浏览器上按键或按键传递不同的东西,一个会给出代码,另一个字符。

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.

一杯敬自由 2024-11-10 05:10:02

基本上,keydown/keyup 事件用于“按键”,而 keypress 事件用于“可打印字符”。如果您想要“字符”,请改用 KeyPressHandler。 Firefox 将触发太多事件(即,即使是不可打印的字符),但您可以轻松判断,因为 charCode 将变为 0。

您是否真的想在 keyup 中执行此操作?

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文