How to track caret/cursor in contenteditable?
===

I'd like to track the movement of the caret/cursor in a contenteditable.  I'm not sure what's the best way to do this, though.

I'm currently listening for click, keydown, keyup.  (keypress of course doesn't even fire for things like arrow keys or ctrl-x.)

While click works fine, the problem with keydown is that it's fired before the caret actually moves, so when I query the current document selection range, I get the old position and not the new one.  But if I rely on keyup to get the updated position, it may fire too late.

This must be possible because things like CKeditor are able to do this.  Any hints?