I was having a play with this script.
And I noticed that Alt Gr's KeyCode is 17 in IE10 and 17 AND 18 in Chrome?
Can someone explain why its not 18 (or a completely new number) and why I get two popups in Chrome?
Heres the code:
document.onkeyup = KeyCheck;
function KeyCheck(e) {
var KeyID = (window.event) ? event.keyCode : e.keyCode;
alert(KeyID);
switch (KeyID)
{
case 18:
document.Form1.KeyName.value = "Alt";
break;
case 17:
document.Form1.KeyName.value = "Ctrl";
break;
}
}
This is not my code, I just stumbled upon it.
EDIT: Having more of a play around I believe Alt Gr means Ctrl + Alt at the same time, as some things that require Alt Gr like é also work with Ctrl + Alt.
Ctrl+Alt. Windows interprets Ctrl + Alt as AltGr , to accommodate some compact keyboards like those of netbooks which have neither the AltGr key or a right-hand Alt key. Thus Ctrl + Alt + a has the same effect as AltGr + a .
Additionally, you can also type in different characters using the left Alt key. For example, you can type in Φ using the 'Alt + 1256' key combination. Alt Gr key: The Alt Gr key on the right side of the keyboard is primarily used to type in certain characters that are not present on the keyboard.
(ALT GRaph key) A key on many international computer keyboards that is located where the right Alt key is normally found (right of the spacebar). When pressed along with a keyboard key, it enables entry of special characters.
To unlock it, you need 2 steps. Press Shift then AltGr and release, this go to Caps Lock, but without indicate it. Press Shift and release, this go back to lowercase.
The Problem is that the alert
halts execution of the code, so the second onkeyup
is not called. By changing the function to
function KeyCheck(e)
{
var KeyID = (window.event) ? event.keyCode : e.keyCode;
switch(KeyID)
{
case 18:
document.Form1.KeyName.value = document.Form1.KeyName.value+"Alt";
break;
case 17:
document.Form1.KeyName.value = document.Form1.KeyName.value+"Ctrl";
break;
}
}
we can see that both Alt
and Ctrl
get called.
Tested with Firefox 22 and IE 9.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With