Discover accented characters printed on a Mac?
I am trying to emulate <input type="text">in SVG by listening to keypresses and keydownto <body>pages.
There seems to be a problem with accented letters on Mac. You must enter a Opt+ e, afor á, and the same goes for the other vowels.
I listen to the body like this (JSFiddle) :
var theElement = document;
theElement.onkeypress = function(e) {
console.log("Press: " + String.fromCharCode(e.keyCode) + " " + e.keyCode);
}
theElement.onkeydown = function(e) {
console.log("Down: " + String.fromCharCode(e.keyCode) + " " + e.keyCode);
}
theElement.onkeyup = function(e) {
console.log("Up: " + String.fromCharCode(e.keyCode) + " " + e.keyCode);
}
On Windows, typing é, I get the following log:
Down: Þ 222 (index): 27
Up: Þ 222 (index): 30
Down: E 69 (index): 27
Press: é 233 (index): 24
Up: E 69 (index): 30
And it works fine. But on Mac, I get:
Down: 18 (index): 27
Down: E 69 (index): 27
Up: E 69 (index): 30
Up: 18 (index): 30
Down: E 69 (index): 27
Press: e 101 (index): 24
Up: E 69
18 - Option, , , , , , e.
, <input type="text">, é, input ( , Mac), - e (JSFiddle):
: 18 (): 27
: å 229 (): 27
: E 69 (): 30
: 18 (): 30
: å 229 (): 27
: E 69 (): 30
, (é, á, ), 229.
, <body> Windows, Windows.
Google Chrome ( , , ).
Halp?!
var theElement = document;
theElement.onkeypress = function(e) {
if (theElement.accent === true)
console.log("Press: " + String.fromCharCode(e.keyCode) + " (accented) " + e.keyCode);
else
console.log("Press: " + String.fromCharCode(e.keyCode) + " " + e.keyCode);
}
theElement.onkeydown = function(e) {
theElement.accent = true;
if (theElement.accent === true)
console.log("Press: " + String.fromCharCode(e.keyCode) + " (accented) " + e.keyCode);
else
console.log("Press: " + String.fromCharCode(e.keyCode) + " " + e.keyCode);
}
theElement.onkeyup = function(e) {
theElement.accent = false;
if (theElement.accent === true)
console.log("Press: " + String.fromCharCode(e.keyCode) + " (accented) " + e.keyCode);
else
console.log("Press: " + String.fromCharCode(e.keyCode) + " " + e.keyCode);
}
, , , - .