键盘按下时正常字符和半角字符的区别 [英] Differency normal characters and half characters on keydown

查看:116
本文介绍了键盘按下时正常字符和半角字符的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们分叉了实验性的Mediawiki VisualEditor.该WYSIWYM编辑器使用隐藏的文本区域和DOM中内容的表示形式.当您将视图聚焦时,焦点将指向文本区域,并且该视图会侦听keydown事件,以将每个键入的字符添加到内容中,然后清空文本区域的值.

We forked experimental Mediawiki VisualEditor. This WYSIWYM editor work with a hidden textarea and a representation of the content in DOM. When you focus the view, the focus is given to the textarea, and the view listen to keydown event to add each typed characters to the content, then empty the textarea's value.

仅在Mac OS X上出现半字符问题.如果键入^或¨或需要打印第二个字符的任何字符,则会触发keydown事件.因此,当用户想要一个ê"时,他输入"^".视图获取textarea值('^')并清除textarea值.然后,用户键入"e".视图显示"^ e".作为奖励,在Chrome上(在这种情况下为Firefox更好),用户将无法在不重新加载窗口的情况下在任何输入中键入当前页面上的任何重音符号.

The problem occurs with half characters on Mac OS X only. If you type ^or ¨ or any characters which need a second character to be printed, keydown event is fired. So, when user want a 'ê', he types '^'. View get the textarea value ('^') and clean the textarea value. Then, the user type 'e'. The view display '^e'. And as bonus, on Chrome (Firefox is better in this case), user will never be able to type any accents on the current page in any inputs without reloading the window.

有什么办法可以使真实角色和半个角色有所不同吗?

Is there any way to make the difference between a real character and a half one ?

推荐答案

刚刚找到了解决方法.通过侦听keyup事件,死键将返回设置为UnidentifiedkeyIdentifier属性.

Just found a workaround. By listening to keyup event, dead keys returns a keyIdentifier property set to Unidentified.

所以:

keyuphandler = function(e)
{
    if (e.keyIdentifier === 'Unidentified')
    {
        return;
    }
    doSomething();
}

这篇关于键盘按下时正常字符和半角字符的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆