Hi Mathieu,
You are in luck!
I just checked in a big change yesterday that makes KeyboardEvent
handling better. The short version is check out the
KeyboardEventController class
http://api.dartlang.org/docs/bleeding_edge/dart_html/KeyboardEventController.html
which provides both the keyCode AND the charCode whenever possible/it
makes sense (unlike JS, which only provides one). Its usage is a
little non-standard currently because this is an experimental feature
right now (and probably buggy, since I don't have a bunch of
international keyboards to test with. File bugs as you see them!).
Here's how you use it:
import 'dart:html';
myCustomKeyHandler(KeyEvent e) {
print('The charCode is ${e.charCode}');
print('The keyCode is ${e.keyCode}');
}
main() {
var controller = new KeyboardEventController.keydown(document.window);
controller.add(myCustomKeyHandler);
});
---------
If you don't want to use my new fancy-pants KeyboardEvent controller
for handling events, you can handle events with the regular
KeyboardEvent class, which will behave exactly like JavaScript
keyboard events:
import 'dart:html';
myCustomKeyHandler(KeyboardEvent e) {
print('The charCode is ${e.charCode}');
print('The keyCode is ${e.keyCode}');
}
main() {
document.window.on.keyDown.add(myCustomKeyHandler, false);
});
There is one small catch, though. Like in JavaScript, you can't
programmatically create full-fledged new KeyboardEvents without the
user actually pressing on the Keyboard. So you could write
var event = new KeyboardEvent('keyup', document.window);
document.window.on.keyUp.dispatch(event);
http://api.dartlang.org/docs/bleeding_edge/dart_html/KeyboardEvent.html#KeyboardEvent
but there is the caveat that this event is not going to be fully
populated with values like keyCode and charCode that a real
user-generated keyboard event will have.
Hope this helps!
Emily
> --
> Consider asking HOWTO questions at Stack Overflow:
>
http://stackoverflow.com/tags/dart
>
>