String.fromCharCode & CharacterSets

Recently, I tried to reflect some input into input (text) fields. Using

 String.fromCharCode(event.which)

for example, correctly translates all the "standard" characters. Well, that translates them all in uppercase, but you can easily catch by also looking at the toggle key.

My problem is that it cannot translate characters like dots, commas, question marks, etc. The first assumption was that I should define a character encoding set, but that doesn't seem to help. Maybe it is completely disconnected?

Yours faithfully

- Andy

+3
source share
1 answer

, keyup keydown, , , , . a a, 65 key code.

keypress, , , :

document.getElementById('inputId').onkeypress = function (e) {
  e = e || window.event;
  var keyCode = e.keyCode || e.which;
  alert(keyCode);
};

.   

+5

Source: https://habr.com/ru/post/1742231/


All Articles