How Can I Convert Google Chrome's .keyidentifier To Something Reasonable?
So I was doing a script that captures key presses. It's not so easy, because no browser seems to actually follow the specification of keyboard events. In firefox, I can observe key
Solution 1:
The actual code is:
//Google chrome retardednessif(event.keyIdentifier) {
keyCode = parseInt(event.keyIdentifier.substr(2), 16);
}
//not that the other browsers are any closer to something systematic and logicalelse {
keyCode = event.keyCode;
}
Solution 2:
I haven't worked with keyboard events for Firefox or Chrome yet, but from the example you posted it seams like Chrome gives you the Unicode representation of the letter 'A' (where the number part is hexadecimal) while Firefox gives you the same number in base 10 (decimal). Making them consistent with each other should therefor be as simple as converting the Firefox number to hexadecimal so you can use the Unicode representation in both browsers.
Post a Comment for "How Can I Convert Google Chrome's .keyidentifier To Something Reasonable?"