JSFiddle - React, Tailwind, and code Playground

https://gist.github.com/nantekkotai/4602401 http://hondou.homedns.org/pukiwiki/pukiwiki.php?Javascript%20IME%C6%FE%CE%CF%C3%E6%A4%CE%C8%BD%C4%EA

by FiNGAHOLiC

HTML

<textarea class="js-textarea"></textarea>

JavaScript

$(function(){
    
    var $textarea = $('.js-textarea').on('keypress keydown keyup', function(e){
        if (!getIMEMode(e) && e.type === 'keyup') {
            console.log('実行');
        }
    });
    
    var keyPressCount = 0;
    
    var getIMEMode = function(e){
        
        var onIMEMode;
        var type = e.type;
        var keyCode = e.keyCode;
        
        // keypressイベントでなおかつ変換中のスペース(241と242でない場合)
        if ((type === 'keypress') && (keyCode != 241) && (keyCode != 242)) {
            keyPressCount++;
        } else if (type === 'keyup') {
            keyPressCount--;
            if (keyPressCount < 0) {
                if (keyCode == 13) {
                    // IME確定;
                    onIMEMode = false;
                } else {
                    // IME入力中;
                    onIMEMode = true;
                }
                keyPressCount = 0;
            } else {
                // 直接入力中;
                onIMEMode = false;
            }
        }
        return onIMEMode;
    };
});