Determine if a keystroke caused a printable Unicode character to be entered without obsolete APIs

The recommended way to go forward is to keep the predefined keyvalues as a blacklist and assume that the printable character does not exist? How will this work for keyboards with special / programmable keys?

When you try to capture printable characters on not input|textarea|select|contenteditableat the moment, only non-hacks are used (without incomplete ranges or blacklists, as can be seen from many similar questions), without using obsolete functions to use hidden input/ textareaand use its value to capture characters that actually change is that value?

+4
source share
2 answers

Well, after looking at it for some time, the answer is this: you cannot define this without relying on legacy APIs or textareahack.

Of course, they are unlikely to ever disappear, but if someone finishes searching for a way to do this without them, they will not find it.

key, , - , .

+1

key:

:

const isPrintableChar = e.key.length === 1 && e.key !== ' ';
const noModifier = !e.ctrlKey && !e.metaKey && !e.altKey;
return isPrintableChar && !noModifier;

e.which .

+1

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


All Articles