Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Alt Gr have the same keyCode as Ctrl?

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.

like image 961
Adam Avatar asked Jul 25 '13 11:07

Adam


People also ask

Is Ctrl Alt same as AltGr?

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 .

What is the difference between Alt and Alt Gr key in keyboard?

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.

What key is ALT GR?

(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.

How do I unlock Alt Gr key?

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.


1 Answers

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.

like image 192
Dahaka Avatar answered Nov 15 '22 17:11

Dahaka