-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathSimulateIEKeyEventExample01.htm
42 lines (34 loc) · 1.26 KB
/
SimulateIEKeyEventExample01.htm
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
33
34
35
36
37
38
39
40
41
42
<!DOCTYPE html>
<html>
<head>
<title>Simulating IE Keyboard Events Example</title>
<script type="text/javascript" src="EventUtil.js"></script>
</head>
<body>
<input type="text" value="" id="myTextbox" />
<input type="button" value="Send keypress to the textbox" id="myBtn" />
<p>This example works in IE though no text will appear in the textbox.</p>
<script type="text/javascript">
(function(){
var btn = document.getElementById("myBtn");
var textbox = document.getElementById("myTextbox");
EventUtil.addHandler(textbox, "keypress", function(event){
event = EventUtil.getEvent(event);
var charCode = EventUtil.getCharCode(event);
alert(charCode);
});
EventUtil.addHandler(btn, "click", function(event){
//create event object
var event = document.createEventObject();
//initialize the event object
event.altKey = false;
event.ctrlKey = false;
event.shiftKey = false;
event.keyCode = 65;
//fire the event
textbox.fireEvent("onkeypress", event);
});
})();
</script>
</body>
</html>