欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

JS的中文输入法下KeyDown()的keyCode值总为229

程序员文章站 2022-06-01 12:38:35
...
 $(document).keydown(function (e) {
            var currKey = 0, CapsLock = 0, e = e || event;
            theKey = e.keyCode || e.which || e.charCode;
            var tdate = new Date();
            var ttime = tdate.getTime();  //整体毫秒数
            keystring += "(tool:key,Action:keydown,value:" + String.fromCharCode(theKey) + ",time:" + ttime + "),";
        });
        $(document).keyup(function (e) {
            var currKey = 0, CapsLock = 0, e = e || event;
            theKey = e.keyCode || e.which || e.charCode;
            var tdate = new Date();
            var ttime = tdate.getTime();
            keystring += "(tool:key,Action:keyup,value:" + String.fromCharCode(theKey) + ",time:" + ttime + "),"
        });

在获得键盘keydown和keyup时,keyup获得的数据正常,而keydown却一直是229,这是因为中文输入法会转换,目前还不是很清楚,先记下来,查找到结果后再补充

转载于:https://my.oschina.net/ZoeyZhong/blog/1836536