S
Steve Dearth
I have an application that closely monitors keyboard events and responds to
specific keypress combinations. This application works fine on Windows XP
with an English keyboard layout (under both Internet Explorer 6.0 and
Mozilla 1.3+). When I use the Polish Input Method Editor to enter special
characters, I see very strange behavior.
Normally, pressing either <alt> key results in a keyCode of 18, and a
<ctrl> key press results in a keyCode of 17. When using the Polish IME
with Internet Explorer, pressing the left <alt> key still results in an 18,
but the right <alt> gives me a 17. Even worse, the event's ctrlLeft
attribute is true. This means that when using the IME, I can't distinguish
between a right alt key and a left ctrl key.
Has anyone seen this behavior, and does anyone have any idea how to
correctly determine the correct keypress when using an IME? Below is a
short test case that demonstrates the behavior:
<html>
<head>
<script>
function handler(e) {
if (!e) e = window.event;
if (window.event) {
var info = "keyCode = " + e.keyCode + "\n";
info += "altLeft = " + e.altLeft + "\n";
info += "altKey = " + e.altKey + "\n";
info += "ctrlKey = " + e.ctrlKey + "\n";
info += "ctrlLeft = " + e.ctrlLeft + "\n";
alert(info);
}
}
function init() {
document.onkeydown = handler;
}
</script>
<body onLoad="init();">
To test keyboard events, view this page with Internet Explorer.<br>
With focus on the browser, hit a key. An alert box will appear<br>
with information regarding the keypress event received by the<br>
event handler.<p>
The keyCodes should be as follows:
<ul>
<li>Shift: 16</li>
<li>Control: 17</li>
<li>Alt: 18</li>
</ul>
Notice that when using the Polish Programmer's keyboard, the<br>
right alt key (AltGr) is reported to JavaScript as a left<br>
control key.
</body>
</html>
specific keypress combinations. This application works fine on Windows XP
with an English keyboard layout (under both Internet Explorer 6.0 and
Mozilla 1.3+). When I use the Polish Input Method Editor to enter special
characters, I see very strange behavior.
Normally, pressing either <alt> key results in a keyCode of 18, and a
<ctrl> key press results in a keyCode of 17. When using the Polish IME
with Internet Explorer, pressing the left <alt> key still results in an 18,
but the right <alt> gives me a 17. Even worse, the event's ctrlLeft
attribute is true. This means that when using the IME, I can't distinguish
between a right alt key and a left ctrl key.
Has anyone seen this behavior, and does anyone have any idea how to
correctly determine the correct keypress when using an IME? Below is a
short test case that demonstrates the behavior:
<html>
<head>
<script>
function handler(e) {
if (!e) e = window.event;
if (window.event) {
var info = "keyCode = " + e.keyCode + "\n";
info += "altLeft = " + e.altLeft + "\n";
info += "altKey = " + e.altKey + "\n";
info += "ctrlKey = " + e.ctrlKey + "\n";
info += "ctrlLeft = " + e.ctrlLeft + "\n";
alert(info);
}
}
function init() {
document.onkeydown = handler;
}
</script>
<body onLoad="init();">
To test keyboard events, view this page with Internet Explorer.<br>
With focus on the browser, hit a key. An alert box will appear<br>
with information regarding the keypress event received by the<br>
event handler.<p>
The keyCodes should be as follows:
<ul>
<li>Shift: 16</li>
<li>Control: 17</li>
<li>Alt: 18</li>
</ul>
Notice that when using the Polish Programmer's keyboard, the<br>
right alt key (AltGr) is reported to JavaScript as a left<br>
control key.
</body>
</html>