How to dispatch an KeyboardEvent with specific KeyCode
Can't use dispatchEvent
. Try:
import 'dart:async';import 'dart:html';void main() { Stream stream = KeyEvent.keyPressEvent.forTarget(document.body); stream.listen((KeyEvent keyEvent){ if(keyEvent.keyCode == KeyCode.ESC) { // do stuff } }); stream.add(new KeyEvent('keypress', keyCode: KeyCode.ESC));}
as described in https://api.dartlang.org/apidocs/channels/stable/dartdoc-viewer/dart:html.KeyEvent