You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What is the current behavior?
I'm a Chinese developer, our character looks like 你好,.
To input those characters, we have a program to process combinations of the single key down.
For example, I want to input 你, I will input a combination of keys ni, and then select the character 你 from the program. In the browser environment this cannot be seen(if I'm inputting in an input DOM, the value of it will not be changed until the last step).
I simplified the problem and put it on the codesandbox code
I just listen to the input's 'keydown' event through the onKeyDown and print what key I've pressed.
In chrome, the key is Unidentified, keyCode is 229, In firefox key is Process. ONLYa-zA-z0-9 behave unusual, keys like ctrl, shift work fine.
My input program has two modes, one is English, another is Chinese.
And I find that if I turn my input program on, no matter what mode it is, my code works weird as above.
If I turn the input program off, my code works fine. In my view, with the input program on and set it to English mode, has no differences with turn it off
I also tried add listener on a normal html page like
That is how the key event API works, anything written while the IME is active will have keyCode = 229.
You have to use the input events (onChange in React terms), and also check if their isComposing property is true. I don't think React's synthetic event has all the relevant properties so you probably need to work with the nativeEvent.
Reacted by Sunil Pai, Augustus Yuan, Leo and Junaid Faryad
While some of these keyboards might still use the right values for e.key, e.code, e.keyCode… when pressing certain keys such as arrows or backspace, there’s no guarantee, so your keyboard logic might not always work on mobile devices.
Normally on my mobile device pressing the go(the default ➡️ ) key
onKeyDown sends e.key as "Enter"
but when I change the input's enterKeyHint to enter
it sends Unidentified as e.key
It works with every other keyHints(done ✔️ , next ⏭️ , previous ⏮️ , search 🔍 and send) as well.
only Enter↪ does't work for me.
Is this is expected behaviour? how can I solve this
Thanks :D
Activity
Jessidhia commentedon Jan 9, 2019
That is how the key event API works, anything written while the IME is active will have keyCode = 229.
You have to use the input events (onChange in React terms), and also check if their isComposing property is true. I don't think React's synthetic event has all the relevant properties so you probably need to work with the nativeEvent.
nhunzaker commentedon Jan 18, 2019
@Jessidhia what relevant properties would we need to add?
lzszone commentedon Jan 21, 2019
@Jessidhia You're right, I don't know the difference when
keydownevent betweeninputelement and normal DOM element.@nhunzaker It's my problem, the synthetic event works fine.
Thank you guys.
threepointone commentedon Jan 23, 2019
I hope the issue's resolved for you @lzszone? closing this, please reopen if not. thanks!
joshxyzhimself commentedon Aug 29, 2022
IME here means Input-Method Editor.
Check here for more info: https://javascript.info/keyboard-events#mobile-keyboards
mind0bender commentedon Mar 4, 2023
Normally on my mobile device pressing the go(the default ➡️ ) key
onKeyDown sends e.key as "Enter"
but when I change the input's enterKeyHint to
enterit sends Unidentified as e.key
It works with every other keyHints(done ✔️ , next ⏭️ , previous ⏮️ , search 🔍 and send) as well.
only Enter↪ does't work for me.
Is this is expected behaviour? how can I solve this
Thanks :D