My question is somewhat related to this question. However, I do not have the luxury to listen for the submit event so the answer to that question will not work for me.
My question: Is it possible in Javascript to detect when the Japanese/Chinese suggestion menu is open? Or is there another way to distinguish an Enter keypress that is to accept the Japanese/Chinese character suggestion from any other Enter keypress?
The reason the solution from the other question will not work for my situation is that I am currently overriding the textarea functionality with JavaScript so that an Enter keypress submits the form instead of making a newline.
Therefore I want to be able to distinguish between an Enter keypress that is to accept a character suggestion for Japanese or Chinese and for any other Enter keypress I want to submit the form.
I use the following check to determine whether any keyboard event is happening inside that window (IME)
event.isComposing || event.keyCode === 229
isComposing alone is not enough, as Safari has a bug
keyCode is deprecated
But it's better than nothing, hope it helps!
Using the keydown event instead of the keyup event (discovered in this answer) seems to work in the latest versions of Chrome, Firefox and Safari using the Mac IME. I haven't been able to test it in Explorer or using any other IMEs. If anyone can share results under other browsers or IMEs it would be great to know.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With