Here is my code:
$("input").on({
    keydown: function(ev) {
        if (ev.which === 27){   // esc button
           backspace_emolator();
        } else if (ev.which === 8){   // backspace button
           console.log('backspace button pressed');
        }
    }
});
function backspace_emolator(){
   // remove one character exactly how backspace button does
}<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" name="fname" class="myinput">All I'm trying to do is making esc button exactly the same as backspace button. So I want to remove one character of .myinput's value when <kbd>esc</kbd> is pressed. 
How can I do that?
Note: I don't want to just remove one character of .myinput's value. I want to press backspace button. So backspace button pressed should be shown in the console when I press esc button.
 
     
     
     
    