Is it possible to disable a certain keyboard key (like asterisk or string) by using jquery?
You can't disable a key stroke as such but you could capture it with jQuery and overwrite its action (return false). The example below captures the enter key. Just change 13 to any key code you need to disable.
$("input").keypress(function (evt) {
var keycode = evt.charCode || evt.keyCode;
if (keycode == 13) { //Enter key's keycode
return false;
}
});
I had to disable all the keys but the F11 and ESC. So I did this way. Think this may help someone. :)
$(document).on('keydown',function(e)
{
var key = e.charCode || e.keyCode;
if(key == 122 || key == 27 )
{}
else
e.preventDefault();
});
Handle onKeyDown
, then preventDefault
on it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With