Skip to content

event.key = Unidentified, event.keyCode = 229 #14512

Closed

Description

@lzszone

Happy new year


feature or a bug?
Maybe it's a bug.


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.
ONLY a-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

window.addEventListener('keydown', function(e) {console.log(e.key, e.keyCode)})

This works fine with my input program on.


versions

OS: Ubuntu 18.04 with the latest update
Input program: Ibus-libpinyin(github)
Browser: Chrome 71.0.3578.98, Firefox 64.0
React: 16.7.0

Activity

  1. Jessidhia commented on Jan 9, 2019

    @Jessidhia
    Contributor

    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.

  2. nhunzaker commented on Jan 18, 2019

    @nhunzaker
    Contributor

    @Jessidhia what relevant properties would we need to add?

  3. lzszone commented on Jan 21, 2019

    @lzszone
    Author

    @Jessidhia You're right, I don't know the difference when keydown event between input element and normal DOM element.

    @nhunzaker It's my problem, the synthetic event works fine.

    Thank you guys.

  4. threepointone commented on Jan 23, 2019

    @threepointone
    Contributor

    I hope the issue's resolved for you @lzszone? closing this, please reopen if not. thanks!

  5. joshxyzhimself commented on Aug 29, 2022

    @joshxyzhimself

    IME here means Input-Method Editor.

    When using virtual/mobile keyboards, formally known as IME (Input-Method Editor), the W3C standard states that a KeyboardEvent’s e.keyCode should be 229 and e.key should be "Unidentified".

    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.

    Check here for more info: https://javascript.info/keyboard-events#mobile-keyboards

  6. mind0bender commented on Mar 4, 2023

    @mind0bender

    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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions