在按键上检测Alt Gr(Alt Graph)修改器 [英] Detect Alt Gr (Alt Graph) modifier on key press

查看:224
本文介绍了在按键上检测Alt Gr(Alt Graph)修改器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在javascript Event 对象中,有一些布尔值用于检查是否按下了修饰键:


  • ctrlKey CTRL
  • altKey ALT 键。

  • altLeft :< kbd>左键。仅适用于IE。

  • altGraphKey ALTGR 键。仅限于Chrome / Safari。



然而,有一些问题:


  • IE和铬组中ctrlKey 方altKey 真正当你按下ALTGR修改。

  • 火狐套中ctrlKey false altKey true 当您按下ALTGR修饰符时,因为只有ALT被按下。

  • Chrome具有 altGraphKey 属性,但它总是未定义



问题:如何可以我之间差的 ALT + CTRL ALTGR 键按下?特别是在Chrome中。

解决方案

webkit浏览器中的altGraphKey不再显示存在(截至2013年9月)已经改变。 AltGr键的浏览器行为目前看起来是:
$ b $ ul

  • Webkit(Chrome) - ctrlKey:true,altKey:true

  • IE 8 - ctrlKey:false,altKey:true

  • IE 10 - ctrlKey:true,altKey:true

  • Mozilla Firefox) - ctrlKey:true,altKey:true



  • 也就是说,它们目前都是一致的始终不一致)。



    以下片段应该在现代浏览器中捕捉Alt Gr - 但不是Alt或Ctrl - 。然而,你需要IE8的一个特例:

      if(event.ctrlKey&& event.altKey){
    //显示为Alt Gr
    }


    In the javascript Event object, there are some boolean values to check if modifier keys are pressed:

    • ctrlKey: CTRL key.
    • altKey: ALT key.
    • altLeft: ALT left key. Only for IE.
    • altGraphKey: ALTGR key. Only for Chrome/Safari.

    However, there are some issues:

    • IE and Chrome set ctrlKey to true and altKey to true when you press the ALTGR modifier.
    • Firefox sets ctrlKey to false and altKey to true when you press the ALTGR modifier, as only ALT has been pressed.
    • Chrome has the altGraphKey property, but it is always undefined.

    Question: how can I difference between an ALT+CTRL or an ALTGR key press? Specially in Chrome.

    解决方案

    The altGraphKey in webkit browsers no longer appears to exist (as at September 2013) and the behaviour of Firefox has changed. Browser behaviours for the AltGr key currently appear to be:

    • Webkit (Chrome) - ctrlKey: true, altKey: true
    • IE 8 - ctrlKey: false, altKey: true
    • IE 10 - ctrlKey: true, altKey: true
    • Mozilla (Firefox) - ctrlKey: true, altKey: true

    Which is to say, they are all currently consistent (apart from IE8, which remains consistently inconsistent).

    The following snippet should catch Alt Gr - but not Alt or Ctrl - in modern browsers. You will need a special case for IE8 however:

    if (event.ctrlKey && event.altKey) {
        // Appears to be Alt Gr
    }
    

    这篇关于在按键上检测Alt Gr(Alt Graph)修改器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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