Translate Javascript keyCode into charCode for non-U.S. keyboard layout (i.e. azerty)

前端 未结 2 827
梦谈多话
梦谈多话 2020-12-24 09:32

Quick background:

  • when a key is pressed in a browser, three events are generated: keyDown, keyPress and keyUp
2条回答
  •  执笔经年
    2020-12-24 10:05

    This is an absolute minefield and I would urge you not to attempt this if you can possibly avoid it. Not only is there a long and tangled history of browser manufacturers not agreeing on key event behaviour, there is also the fact that they still don't agree and are still regularly changing the key behaviour of their browsers.

    The following is the best I can offer and the definitive resource on browser key events: http://unixpapa.com/js/key.html

    If you have to do this, I think you're going to end up with loads of key code mapping tables that will go out of date very quickly. Good luck.

提交回复
热议问题