test-console-output-events.html 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <!DOCTYPE HTML>
  2. <html dir="ltr" lang="en-US">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Test the web console output for DOM events</title>
  6. <!--
  7. - Any copyright is dedicated to the Public Domain.
  8. - http://creativecommons.org/publicdomain/zero/1.0/
  9. -->
  10. </head>
  11. <body>
  12. <p>hello world!</p>
  13. <script type="text/javascript">
  14. function testDOMEvents() {
  15. function eventLogger(ev) {
  16. console.log("eventLogger", ev);
  17. }
  18. document.addEventListener("mousemove", eventLogger);
  19. document.addEventListener("keypress", eventLogger);
  20. synthesizeMouseMove();
  21. synthesizeKeyPress("a", {shiftKey: true});
  22. }
  23. function synthesizeMouseMove(element) {
  24. var mouseEvent = document.createEvent("MouseEvent");
  25. mouseEvent.initMouseEvent("mousemove", true, true, window, 0, 0, 0, 0, 0,
  26. false, false, false, false, 0, null);
  27. document.dispatchEvent(mouseEvent);
  28. }
  29. function synthesizeKeyPress(key, options) {
  30. var keyboardEvent = document.createEvent("KeyboardEvent");
  31. keyboardEvent.initKeyEvent("keypress", true, true, window, false, false,
  32. options.shiftKey, false, key.charCodeAt(0), 0);
  33. document.dispatchEvent(keyboardEvent);
  34. }
  35. </script>
  36. </body>
  37. </html>