I use the M1 release and wrote a key handler that looks like this:
void _onKeyPress(KeyboardEvent e) { switch (e.keyIdentifier) { case KeyName.UP: case KeyName.LEFT: e.preventDefault(); prev(); break; case "U+0020": // FIXME Must be a better way, or? case KeyName.DOWN: case KeyName.RIGHT: e.preventDefault(); next(); break; } }
It works fine in Chrome, but not in FF or IE. There must be a better way to deal with the gap and still keep it in one switch, right? I know that I can look at other fields to get space, but this is also not a good alternative (since then I would decompose the code into two switch statements.) In any case, the problem with it does not work in FF and IE is worse If I rewrite using keyCode , then it works fine in all browsers.
void _onKeyPress(KeyboardEvent e) { switch (e.keyCode) { case 38: case 37: e.preventDefault(); prev(); break; case 32: case 40: case 39: e.preventDefault(); next(); break; } }
My problem is that I cannot find constants for virtual key codes. Am I doing something wrong? What is the best way to handle Dart-compatible cross-browser key events?
source share