1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
<script>
window.addEventListener("Test:DispatchKeyEvents", aEvent => {
var keyCode = KeyEvent["DOM_" + aEvent.detail.code];
document.body.focus();
var evt = document.createEvent("KeyboardEvent");
evt.initKeyEvent("keydown", true, true, window,
false, false, false, false,
keyCode, 0);
document.body.dispatchEvent(evt);
evt = document.createEvent("KeyboardEvent");
evt.initKeyEvent("keypress", true, true, window,
false, false, false, false,
keyCode, 0);
document.body.dispatchEvent(evt);
evt = document.createEvent("KeyboardEvent");
evt.initKeyEvent("keyup", true, true, window,
false, false, false, false,
keyCode, 0);
document.body.dispatchEvent(evt);
});
</script>
</body>
</html>
|