Me parece que ha respondido a su propia pregunta. Si está detectando la tecla SHIFT, podrá distinguir entre el capital y minúsculas:
if(e.shiftKey){
alert("You pressed a CAPITAL letter with the code " + e.keyCode);
}else{
alert("You pressed a LOWERCASE letter with the code " + e.keyCode);
}
o estoy malentendido su pregunta?
Actualización: códigos caso ASCII superiores se pueden convertir fácilmente para bajar códigos caso ASCII mediante la adición de 32, por lo que todo lo que necesita hacer es lo siguiente:
<html>
<head>
<title>Test</title>
<script type="text/javascript">
function showChar(e){
if(e.keyCode!=16){ // If the pressed key is anything other than SHIFT
if(e.keyCode >= 65 && e.keyCode <= 90){ // If the key is a letter
if(e.shiftKey){ // If the SHIFT key is down, return the ASCII code for the capital letter
alert("ASCII Code: "+e.keyCode);
}else{ // If the SHIFT key is not down, convert to the ASCII code for the lowecase letter
alert("ASCII Code: "+(e.keyCode+32));
}
}else{
alert("ASCII Code (non-letter): "+e.keyCode);
}
}
}
</script>
</head>
<body onkeydown="showChar(event);">
<p>Press any character key, with or without holding down
the SHIFT key.<br /></p>
</body>
</html>
Actualización 2: Prueba esto:
<html>
<head>
<title>Test</title>
<script type="text/javascript">
function showChar(e){
if(e.keyCode!=16){ // If the pressed key is anything other than SHIFT
c = String.fromCharCode(e.keyCode);
if(e.shiftKey){ // If the SHIFT key is down, return the ASCII code for the capital letter
alert("ASCII Code: "+e.keyCode+" Character: "+c);
}else{ // If the SHIFT key is not down, convert to the ASCII code for the lowecase letter
c = c.toLowerCase(c);
alert("ASCII Code: "+c.charCodeAt(0)+" Character: "+c);
}
}
}
</script>
</head>
<body onkeydown="showChar(event);">
<p>Press any character key, with or without holding down
the SHIFT key.<br /></p>
</body>
</html>
Pero no debería cambiar el código clave, también? Necesito diferenciar de keyCode u otra cosa como valor. En ambos ejemplos, el código clave es el mismo. Busco una forma que proporcione una clave diferenteCódigos para mayúscula A y minúscula a presionada. –
Echa un vistazo a la actualización de mi respuesta anterior. Creo que eso es lo que estás buscando. – Computerish
Gracias eso es bastante cercano a mi necesidad. Pero, ¿cómo puedo agregar soporte para UTF-8? Digamos por capital Ü y smallcase ü arroja la alerta "ASCII Code (non-letter)". ¿Es posible diferenciar las letras de Unicode de las pequeñas letras en onkeydown? –