Wygląda na to, że odpowiadasz na własne pytanie. Jeśli wykrywanie klawisz SHIFT, można łatwo odróżnić kapitału i małymi literami:
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);
}
Albo ja nieporozumienia Twoje pytanie?
Aktualizacja: Górny Kody przypadek ASCII można łatwo przekształcić w celu obniżenia kody przypadek ASCII poprzez dodanie 32, więc wszystko co musisz zrobić to:
<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>
Aktualizacja 2: Spróbuj tego:
<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>
ale nie powinny zmiana keyCode też? Chcę uzyskać różnicę od keyCode lub coś innego jako wartość. W obu przykładach kod klucza jest taki sam. Poszukuję sposobu, który zapewnia inny klucz klucza dla kapitału A i małe litery wciśnięty. –
Proszę spojrzeć na aktualizację powyższej odpowiedzi. Myślę, że tego właśnie szukasz. – Computerish
Dzięki, że jest bardzo blisko mojej potrzeby. Ale jak mogę dodać obsługę UTF-8? Powiedz o kapitale Ü i małymi literami ü zgłasza alert "Kod ASCII (bez litery)". Czy możliwe jest odróżnienie pisaków caption Unicode od małych liter w onkeydown. –