Why is the keypress event not passed to the GWT method TextInputCell.onBrowserEvent ()?

Question:

I am redefining the GWT method TextInputCell.onBrowserEvent()to try to apply filtering to characters entered in the field. How can I not get the actual character that the user entered in the event keydown?

What I tried:

I can use the method NativeEvent.getKeyCode()to get the key code, but this is not enough, because I want to know the specific character that they typed, so I can compare the character with a regular expression. As far as I understand, keyCode just tells me the key that they typed on the keyboard, so I can’t distinguish between capital “A” and lowercase “a”. I can also capture the value from InputElementin the event keyup, but it's too late because the symbol has already been rendered by the user interface element.

When I call NativeEvent.getCharCode(), it returns 0 for any character I. I tried this in Chrome and Firefox. Why getCharCode()always returns 0? This is mistake?

For example, here is what I tried, and the values ​​that I get when I type the number "1" on the keyboard:

event.getKeyCode() - 49
event.getCharCode() - 0
Character.toChars(event.getCharCode())[0] - (a box character because charCode was 0)
String.valueOf(Character.toChars(event.getCharCode())) - (a box character because charCode was 0)
String.valueOf((char) event.getKeyCode()) - 1

Update:

, , keypress, keydown, event.getType() , , keypress . : keypress? TextInputCell.onBrowserEvent(), TextInputCell.

+1
2

, , AbstractCell , "consumedEvents". , . TextInputCell keyup. AbstractInputCell , keydown. TextInputCell .

TextInputCell keypress . , . GWT, TextInputCell.

GWT: http://code.google.com/p/google-web-toolkit/issues/detail?id=5891

+2

. key code vs char.

'A' vs 'a', NativeEvent.getShiftKey(), , shift. , NativeEvent.getCtrlKey() NativeEvent.getMetaKey().

0

Source: https://habr.com/ru/post/1786226/


All Articles