简体   繁体   中英

how to detect multi-byte characters inputting end by JavaScript?

Currently, I listen on the Enter key to start sending a message.

But for multi-byte characters, the Enter key is supposed to choose a certain character.

The problem is that I've no idea how to detect whether a user is in the middle of inputting a multi-byte character, and even if he's in that process, the message will be sent the first time he presses the Enter key.

So the user experience is really strange.

Does anyone have a solution to this?

If you don't get what I mean above, can try to chat here, and once you started a conversation, switching to multi-byte mode, then you'll know what I mean.

The link is here:

http://maishudi.com/OMegle.php

I'm assuming your reference to multibyte input is a reference to "Input Methods" (or "Input Method Editors" on Windows).

Unfortunately, there isn't any real solution at the moment -- DOM3 was going to add mechanisms for this but it seems to have dropped this due to the complexity.

Part of the complexity comes from the vastly different behaviour of individual input methods before you even consider the behaviour discrepancy between browsers. A good example is to just check what key events you receive for a set of behaviour with Japanese, Korean, and (traditional and simplified) Chinese. The browsers cannot avoid this as they are responding to events fired directly by the input editors.

The only things you can really rely on are keyDown events, and even then not so much in opera and Firefox -- Safari and IE both provide keyDown events during IME composition, with a charCode of 229, and a keyUp event with a charCode corresponding to the actual key that was pressed.

There is a textInput event, but that is only supported by Safari (and by proxy Chrome should support it as well), but it's not substantially better than standard events anyway :-/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM