Skip to content

Instantly share code, notes, and snippets.

@csharpforevermore
Last active August 29, 2015 14:26
Show Gist options
  • Save csharpforevermore/4be6b5355b4051ebf2e1 to your computer and use it in GitHub Desktop.
Save csharpforevermore/4be6b5355b4051ebf2e1 to your computer and use it in GitHub Desktop.
Get key pressed inside an input box
$('input#expectedIncome').keypress(function() {
var e = window.event || e;
var keyUnicode = e.charCode || e.keyCode;
if (e !== undefined) {
switch (keyUnicode) {
case 13: break; // Enter
case 16: break; // Shift
case 17: break; // Ctrl
case 18: break; // Alt
case 27: this.value = ''; break; // Esc: clear entry
case 35: break; // End
case 36: break; // Home
case 37: break; // cursor left
case 38: break; // cursor up
case 39: break; // cursor right
case 40: break; // cursor down
case 78: break; // N (Opera 9.63+ maps the "." from the number key section to the "N" key too!) (See: http://unixpapa.com/js/key.html search for ". Del")
case 110: break; // . number block (Opera 9.63+ maps the "." from the number block to the "N" key (78) !!!)
case 190: break; // .
// default: $(this).formatCurrency({ colorize: true, negativeFormat: '-%s%n', roundToDecimalPlace: -1, eventOnDecimalsEntered: true });
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment