Key codes are pretty good for little things, but they break down pretty quickly if you want international support. In Mathquill, we ended up just using a hidden textarea and a setTimeout, with a few hilarious hacks. The comments and commit history are worth a read: <a href="https://github.com/mathquill/mathquill/blob/dev/src/textarea.js" rel="nofollow">https://github.com/mathquill/mathquill/blob/dev/src/textarea...</a>