gecko-dev/devtools/client/webconsole/test/test-console-output-events....

43 строки
1.2 KiB
HTML

<!DOCTYPE HTML>
<html dir="ltr" lang="en-US">
<head>
<meta charset="utf-8">
<title>Test the web console output for DOM events</title>
<!--
- Any copyright is dedicated to the Public Domain.
- http://creativecommons.org/publicdomain/zero/1.0/
-->
</head>
<body>
<p>hello world!</p>
<script type="text/javascript">
function testDOMEvents() {
function eventLogger(ev) {
console.log("eventLogger", ev);
}
document.addEventListener("mousemove", eventLogger);
document.addEventListener("keypress", eventLogger);
synthesizeMouseMove();
synthesizeKeyPress("a", {shiftKey: true});
}
function synthesizeMouseMove(element) {
var mouseEvent = document.createEvent("MouseEvent");
mouseEvent.initMouseEvent("mousemove", true, true, window, 0, 0, 0, 0, 0,
false, false, false, false, 0, null);
document.dispatchEvent(mouseEvent);
}
function synthesizeKeyPress(key, options) {
var keyboardEvent = document.createEvent("KeyboardEvent");
keyboardEvent.initKeyEvent("keypress", true, true, window, false, false,
options.shiftKey, false, key.charCodeAt(0), 0);
document.dispatchEvent(keyboardEvent);
}
</script>
</body>
</html>