What we have:
keydown
event +preventDefault
preventskeypress
event (proof: https://stackoverflow.com/a/57401334/9398364)stopPropagation
doesn't help at all- We can't simulate keypress with dispatchEvent because we don't know full list of unprintable
event.key
values (which we can't just throw as unicode value usingevent.key.codePointAt(0)
)
What we need:
Disable default browser keys reaction (i.e.
tab
press in chrome) without huge switch expressionDetect
keydown
events because we needshift
,ctrl
and other keys events (event.code
matters)Detect
keypress
events because we need to input unicode characters (event.key
matters) withoutinput
event and without checking if it is unprintable character (such asshift
andctrl
)
How?
UPD: Seems like non-unicode event.key has >1 length (source: https://stackoverflow.com/a/70401792/9398364) Is there any proof?