1

Someone report this issue on github: dead keys on MacOS, In my code I use keypress event to insert characters (and keydown for shortcuts) using:

$(document.documentElement || window).bind('keypress.cmd', function(e) {
    ...
    self.insert(String.fromCharCode(e.which));
    ...
});

anybody have experience in fixing this in an app using jQuery? it seems that on that keyboard only keydown is fired but not keypress.

Is this the only solution: How can I eliminate dead keys on Mac OS X with international keyboard?

Community
  • 1
  • 1
jcubic
  • 61,973
  • 54
  • 229
  • 402

1 Answers1

1

Dead keys appear to fire only keydowns and ups for the key itself + a complete sequence for the actual char. Here's a sequence when pressing dead ^ + u (resulting û):

down   192 c0 À
up     192 c0 À
down   85 55 U
press  117 75 u
up     85 55 U

Here's the dead ´ + u (=ú)

down   187 bb »
up     187 bb »
down   85 55 U
press  117 75 u
up     85 55 U

The backtick is entered with Shift, so the sequence is

down   16 10 
down   187 bb »
up     187 bb »
up     16 10 
down   85 55 U
press  117 75 u
up     85 55 U

http://jsfiddle.net/r8dMu/

(german layout / osx10.9 / Chrome).

So, the workaround could be like this:

document.body.onkeydown  = function(e) { 
    if(e.which == 229) {
       input.value += "^";
       e.preventDefault();
    }
    if(e.which == 187 && e.shiftKey) {
       input.value += "`";
       e.preventDefault();
    }
}
gog
  • 10,367
  • 2
  • 24
  • 38
  • Great explanation, it seems that I din't know excacty what those dead keys where. But you're code is not excatly what I need because I want to insert `ú` so in my case I need to detect, if there was no keypress, in keyup for those keys and if no then I need to process keys in next keypress. – jcubic May 28 '14 at 13:42