Changing the keypress

You can’t change the character or key associated with a key event, or fully simulate a key event. However, you can handle the keypress yourself and manually insert the character you want at the current insertion point/caret. I’ve provided code to do this in a number of places on Stack Overflow. For a contenteditable element:

Here’s a jsFiddle example: http://www.jsfiddle.net/Ukkmu/4/

For an input:

Cross-browser jsFiddle example: http://www.jsfiddle.net/EXH2k/6/

IE >= 9 and non-IE jsFiddle example: http://www.jsfiddle.net/EXH2k/7/

Leave a Comment