尝试获取ENTER键的字符代码 [英] Trying to get the char code of ENTER key

查看:135
本文介绍了尝试获取ENTER键的字符代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  newSymbolTextBox.addKeyPressHandler(new KeyPressHandler(){
public void onKeyPress( KeyPressEvent事件){
System.out.println(foo =+ KeyCodes.KEY_ENTER);
System.out.println(bar =+ event.getCharCode());
}
});

当我按下ENTER时,我得到这个输出:

  foo = 13 
bar =

我期望 bar = 后的值。任何想法?

解决方案

实际上,价值就在那里。你没有看到任何东西的原因是因为该字符是回车符。我相信回车,只是移动下一行(你可以谷歌它的确切功能)。如果你的谷歌ascii表,你会发现你从 KeyCodes.KEY_ENTER 得到的13对应于CR,即回车符。

I have this this code:

newSymbolTextBox.addKeyPressHandler(new KeyPressHandler() {
  public void onKeyPress(KeyPressEvent event) {
      System.out.println("foo =" + KeyCodes.KEY_ENTER);
  System.out.println("bar =" + event.getCharCode());
  }
});

When I press ENTER I get this output:

foo =13
bar =

I expected a value after bar =. Any idea?

解决方案

The value is, in fact, there. The reason you don't see anything is because the character is a carriage return. The carriage return, I believe, just moves the next line (you can google it's exact function). If you google "ascii table" you will see that the 13 you get from KeyCodes.KEY_ENTER corresponds with CR, the carriage return character.

这篇关于尝试获取ENTER键的字符代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆