Search code examples
javascriptdojokeyeventos-dependent

OS independent keyboard event to character mapping


Obviously, a web application needs to adjust to the user's keyboard settings, right? Is there a way to tell Dojo to make a connection to the actual KeyPress event instead of KeyDown, so we can get the character typed from event.charCode?

Since we live in an international world, with multiple operating systems and what not, this information is not sufficient to find out what character the user actually typed, unless I have some function built into the browser to ask the operating system.

As an example, on a German keyboard on Linux, [ is reached via Alt Gr-8, which sends a keydown for Alt and then a keydown with [. Fine, just ignore the first part. On a windows system with a German keyboard, the second event is for an 8 with ctrlKey and altKey set true. Which I don't think JavaScript code should interpret hard-coded, because with other keyboard settings, this key combo will actually mean a different character.

As another example (probably not connected to Dojo, but rather a different programmer's glitch, sorry for the ranting …), with a US keyboard on mac, you can't type the German character ß within the outlook web interface – because outlook bogusly(!) hijacks the alt key (which on the mac is exclusively used to modify the characters typed) to trigger actions and alt-s is thus remapped to mean send. Typically in the middle of a word, of course.


Solution

  • You can set the 5th dontFix argument passed to dojo.connect() to true, which tells it to let it pass thru as-is without the special handling. See https://github.com/dojo/dojo/blob/master/_base/connect.js#L32