question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

event.key = Unidentified, event.keyCode = 229

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
Jessidhiacommented, 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.

0reactions
joshxyzhimselfcommented, Aug 29, 2022

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

keyCode on android is always 229 - Stack Overflow
The question is only about keycode=229, which is basically emitted for print characters. So one can use onbeforeinput and oninput to resolve those...
Read more >
Input on Android: 229 Unidentified | by gossi - Clark Engineering
most often keyCode is 229; when the event is Unidentified then preventDefault() does not work. We found our research had too many ...
Read more >
Why does android keyboard always return 229? - Sololearn
It always returns 229 because it is a W3C standard to return 229 when an "Input Method Editor" is processing and the event...
Read more >
KeyboardEvent.keyCode - Web APIs - MDN Web Docs
The deprecated KeyboardEvent.keyCode read-only property represents a system and implementation dependent numerical code identifying the ...
Read more >
Virtual Keyboard event.key=Unidentified - Ignition
the event.keyCode looks to always be 229 no matter what button i press on the virtual keyboard. The question becomes how do you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found