I want to process the characters typed by the user for a game (I don’t want to use an input tag with a submit button).
I managed to get the keyCode typed with this code:
window.on.keyPress.add((Event e)
{
window.alert('${e.keyCode},${e.keyIdentifier},${e.charCode}');
});
but I don’t know how to display the character of the key pressed (or even get the character of the key as a string).
In Javascript there is a fromKeyCode() function but not in Dart.
Anyway, I am looking for the simplest way to get the keyboard inputs for processing and I would prefer not have to fiddle with keycodes and such.
You can construct a new string from the character code with String.fromCharCodes().
However it’s certainly not the most efficient to be creating a new string each time a user hits a key depending on your game. If you only expect a few specific characters to be hit and ignore others then you may want to create constant/final variables of character codes to compare the character code from the event.
Keep in mind these don’t account for various situations such a capitalization, or the CTRL or ALT or meta key pressed, etc.