At the beginning I wanted to monitor changes to a <input type="text">
in real time (for example, exactly when the user presses a key). The onChange
event did not work because it is triggered only when the user presses Enter or removes focus from the input element. Then I saw this question on StackOverflow. I tried the code from that answer but the problem is that I do not want to be notified for key presses that do not represent printable characters, so I had to modify it in this way to make it verify that there are printable characters in the events:
...
textInputElement.onKeyDown.listen((KeyboardEvent ev) {
if (new String.fromCharCode(ev.keyCode).length > 0) {
callAFunction();
}
});
...
(+ the same change for the onKeyUp
event)
When I tested this in Dartium I saw that by focusing the input element and then pressing any key, a keydown
event is triggered with ev.keyCode = ev.which = 229
and ev.charCode = 0
. Immediately after this event, another keydown
event is triggered with the correct ev.keyCode = ev.which
of the pressed key and ev.charCode = 0
. I did not understand where this 229 key was coming from but I saw that it is a printable character, å
. I searched the Internet and I have found that others have this issue, and sometimes they are using other programming languages and technologies. One relevant link is this and the chosen fix is in this very small commit - they chose to ignore all events which have keyCode = 229
with the explanation that recent versions of Chrome/Chromium/WebKit started to send these keydown events before every standard keyboard events, and that their meaning is that the user pressed some button. but input method is still processing that or input method editor is processing key input.
My question is, is it OK to ignore keydown
events with keyCode = 229
if new String.fromCharCode(229)
returns the printable character "å
"? I thought about the possible situation of having a real key that produces the same key code and its corresponding character.
I thank you for any kind of help!