Char Codes (Key Codes)

Lista dei codici dei caratteri immessi da tastiera

by Michele Pisani

HTML

<br />
<br />
Digita un tasto all'interno della textbox e visualizza il relativo numero di codice in Javascript.
<br />
<br />
<input  type="text" name="inputKey" id="inputKey" onkeypress="javascript:return false;" onkeydown="javascript:return displayKeyCode(event)">
<br />
<br />
<span id="outputCode" name="outputCode"></span>

JavaScript

function displayKeyCode(evt) {
    var textBox = getResult('inputKey');
    var charCode = (evt.which) ? evt.which : event.keyCode
    textBox.value = String.fromCharCode(charCode);
    if (charCode == 8) textBox.value = "backspace";
    if (charCode == 9) textBox.value = "tab";
    if (charCode == 13) textBox.value = "enter";
    if (charCode == 16) textBox.value = "shift";
    if (charCode == 17) textBox.value = "ctrl";
    if (charCode == 18) textBox.value = "alt";
    if (charCode == 19) textBox.value = "pause/break"; 
    if (charCode == 20) textBox.value = "caps lock";
    if (charCode == 27) textBox.value = "escape";
    if (charCode == 33) textBox.value = "page up";
    if (charCode == 34) textBox.value = "page down";
    if (charCode == 35) textBox.value = "end";
    if (charCode == 36) textBox.value = "home";
    if (charCode == 37) textBox.value = "left arrow";
    if (charCode == 38) textBox.value = "up arrow";
    if (charCode == 39) textBox.value = "right arrow";
    if (charCode == 40) textBox.value = "down arrow";
    if (charCode == 45) textBox.value = "insert";
    if (charCode == 46) textBox.value = "delete";
    if (charCode == 91) textBox.value = "left window";
    if (charCode == 92) textBox.value = "right window";
    if (charCode == 93) textBox.value = "select key";
    if (charCode == 96) textBox.value = "numpad 0";
    if (charCode == 97) textBox.value = "numpad 1";
    if (charCode == 98) textBox.value = "numpad 2";
    if (charCode == 99) textBox.value = "numpad 3"; 
    if (charCode == 100) textBox.value = "numpad 4"; 
    if (charCode == 101) textBox.value = "numpad 5"; 
    if (charCode == 102) textBox.value = "numpad 6";
    if (charCode == 103) textBox.value = "numpad 7";
    if (charCode == 104) textBox.value = "numpad 8"; 
    if (charCode == 105) textBox.value = "numpad 9"; 
    if (charCode == 106) textBox.value = "multiply"; 
    if (charCode == 107) textBox.value = "add"; 
    if (charCode == 109) textBox.value = "subtract";...