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.