Skip to content

Commit 7b7e260

Browse files
committedJul 12, 2012
send mousedown, mouseup, click.
1 parent 4028ac7 commit 7b7e260

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed
 

‎KeyboardSendsClicks.html

+23-12
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@
1616
adddiv();
1717
adddiv();
1818

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+
};
1929
keyStore = {};
2030
document.body.onmousemove = function mousemove(e) { lastMouse = e; };
2131
document.body.onkeydown = function keydown(e) {
@@ -26,23 +36,24 @@
2636
} else if (keyStore.hasOwnProperty(e.keyIdentifier)) {
2737
cachedEvent = keyStore[e.keyIdentifier];
2838
//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);
3742
var target = document.elementFromPoint(cachedEvent.clientX,
3843
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();
4351
}
4452
};
4553
}
4654
</script>
4755
<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.
4859

0 commit comments

Comments
 (0)
Please sign in to comment.