|
16 | 16 | adddiv();
|
17 | 17 | adddiv();
|
18 | 18 |
|
| 19 | + function createMouseEvent(typeString, oldMouseEventTemplate) { |
| 20 | + var e = document.createEvent("MouseEvents"); |
| 21 | + e.initMouseEvent(typeString, true, true, null, 1, |
| 22 | + oldMouseEventTemplate.screenX, |
| 23 | + oldMouseEventTemplate.screenY, |
| 24 | + oldMouseEventTemplate.clientX, |
| 25 | + oldMouseEventTemplate.clientY, |
| 26 | + false, false, false, false, 0, null); |
| 27 | + return e; |
| 28 | + }; |
19 | 29 | keyStore = {};
|
20 | 30 | document.body.onmousemove = function mousemove(e) { lastMouse = e; };
|
21 | 31 | document.body.onkeydown = function keydown(e) {
|
|
26 | 36 | } else if (keyStore.hasOwnProperty(e.keyIdentifier)) {
|
27 | 37 | cachedEvent = keyStore[e.keyIdentifier];
|
28 | 38 | //send a synthetic click
|
29 |
| - ee = document.createEvent("MouseEvents"); |
30 |
| - ee._isSynthetic = true; |
31 |
| - ee.initMouseEvent("click", true, true, null, 1, |
32 |
| - cachedEvent.screenX, |
33 |
| - cachedEvent.screenY, |
34 |
| - cachedEvent.clientX, |
35 |
| - cachedEvent.clientY, |
36 |
| - false, false, false, false, 0, null); |
| 39 | + emousedown = createMouseEvent("mousedown", cachedEvent); |
| 40 | + emouseup = createMouseEvent("mouseup", cachedEvent); |
| 41 | + eclick = createMouseEvent("click", cachedEvent); |
37 | 42 | var target = document.elementFromPoint(cachedEvent.clientX,
|
38 | 43 | cachedEvent.clientY)
|
39 |
| - console.log("Sending a click"); |
40 |
| - if (target) |
41 |
| - target.dispatchEvent(ee) |
42 |
| - e.preventDefault(); |
| 44 | + console.log("Sending mousedown, mouseup, click, to ", target); |
| 45 | + if (target) { |
| 46 | + target.dispatchEvent(emousedown); |
| 47 | + target.dispatchEvent(emouseup); |
| 48 | + target.dispatchEvent(eclick); |
| 49 | + } |
| 50 | + e.preventDefault(); |
43 | 51 | }
|
44 | 52 | };
|
45 | 53 | }
|
46 | 54 | </script>
|
47 | 55 | <body onload=init();>
|
| 56 | +Hover the mouse over a location you will send a click. |
| 57 | +Press CTRL and then any key. |
| 58 | +Move the mouse away, then press that key again to replay the click. |
48 | 59 |
|
0 commit comments