Fix buggy autocomplete behaviour for non-US keyboards

This change moves the code for actually entering data from the keydown handler to the
keypress handler, which can reliably catch the character entered (rather than
the key pressed).

This is my second attempt at
https://meta.discourse.org/t/typing-shows-on-non-us-keyboard-layouts/20449
without doing dangerous refactoring.

This does not fix the issue reported in
https://meta.discourse.org/t/overly-aggresive-emoji-autocomplete/20691/7
as that is a different bug.
reduce number of times caretPosition() is called
Merge pull request #2871 from mamhoff/autocomplete-again

Fix buggy autocomplete behaviour for non-US keyboards