Maybe a solution would be to have a map between keycode(place user pressed on keyboard)
and actual letters/characters/symbols written or their actual UTF-16 code points
different keyboards sometimes write out different characters even if they are positioned on the same place on a keyboard(marked by a keycode).
So, for example, same key(keycode) on the keyboard could be mapped to these symbols/characters/letters.
Ç
- in Spain
ú
- in Italy
#
- in Germany
µ
- in Belgian
Here is a sample code that does not use any mapping to determine what language it could be. But its a start, since it checks keycode, actual character/letter/symbol or glyph, and its UTF-16 code point in integer. Also, as far as I can see, none of the methods and properties are marked as deprecated as far as I could see on MDN, as opposed to which, charCode and keyCode, that are used on some examples out there.
var keyCode;
var character;
var utfCodePointInDecimal
function checkCodes(event) {
var that = event
checkKeyCode(that);
checkChar(that);
charUTFPoint();
console.log("keycode/location on keyboard: " + keyCode);
console.log("character: " + character);
console.log("utf code point: " + utfCodePointInDecimal)
}
function checkKeyCode(e) {
keyCode = e.code;
}
function checkChar(e) {
character = e.key;
}
function charUTFPoint() {
utfCodePointInDecimal = Number(character.codePointAt(0));
}
window.onkeydown = checkCodes;
here is a link to a UTF-16 list of characters. (note, code points are in hex)
http://www.fileformat.info/info/charset/UTF-16/list.htm
And here is a site I found with different mappings per language. It is in C lang I belive, but you can probably use it as a template and the write own mapping in JavaScript
https://beta.docs.qmk.fm/using-qmk/simple-keycodes/reference_keymap_extras