I think the answer to your direct question is that the selectionStart attribute of the input field will tell you where the input cursor is.
function myKeypress() { console.log(this.selectionStart);
Also, looking at selectionEnd , you can see if one or more characters are selected, and not just a simple insertion point.
source share