Disable Any Keyboard Key using JQuery
Hello there.
Some time, you may want to disable any key e.g. "Enter Key" (Keyboard's Enter Key) in your Web Page. You can do this with a small block of JQuery code.
Note:- Please download and Import latest JQuery file. Just Google it or go to the link
https://developers.google.com/speed/libraries/devguide
and find & click on JQuery
and find & click on JQuery
Here is the Code
<script src="Your_JQuery_File_Path_Along_With_Extension.JS" type="text/javascript"></script>
//Can be like this<script src="jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
$('html').bind('keydown', function(e)
{
if(e.keyCode == 13)
{
return false;
}
});
});
</script>
Just replace the code value 13 in above JavaScript code block (if(e.keyCode == 13)) with the code of key you want to disable.
Find the key codes in tables given below:
Keyboard key codes
Key
|
Code
|
Key
|
Code
|
Key
|
Code
|
Key
|
Code
|
|||
| backspace | 8 | 0 | 48 | a | 65 | left window key | 91 | |||
| tab | 9 | 1 | 49 | b | 66 | right window key | 92 | |||
| enter | 13 | 2 | 50 | c | 67 | select key | 93 | |||
| shift | 16 | 3 | 51 | d | 68 | numpad 0 | 96 | |||
| ctrl | 17 | 4 | 52 | e | 69 | numpad 1 | 97 | |||
| alt | 18 | 5 | 53 | f | 70 | numpad 2 | 98 | |||
| pause/break | 19 | 6 | 54 | g | 71 | numpad 3 | 99 | |||
| caps lock | 20 | 7 | 55 | h | 72 | numpad 4 | 100 | |||
| escape | 27 | 8 | 56 | i | 73 | numpad 5 | 101 | |||
| page up | 33 | 9 | 57 | j | 74 | numpad 6 | 102 | |||
| page down | 34 | k | 75 | numpad 7 | 103 | |||||
| end | 35 | l | 76 | numpad 8 | 104 | |||||
| home | 36 | m | 77 | numpad 9 | 105 | |||||
| left arrow | 37 | n | 78 | multiply | 106 | |||||
| up arrow | 38 | o | 79 | add | 107 | |||||
| right arrow | 39 | p | 80 | subtract | 109 | |||||
| down arrow | 40 | q | 81 | decimal point | 110 | |||||
| insert | 45 | r | 82 | divide | 111 | |||||
| delete | 46 | s | 83 | |||||||
| t | 84 | |||||||||
| u | 85 | |||||||||
| v | 86 | |||||||||
| w | 87 | |||||||||
| x | 88 | |||||||||
| y | 89 | |||||||||
| z | 90 |
Key
|
Code
|
Key
|
Code
|
|
| f1 | 112 | num lock | 144 | |
| f2 | 113 | scroll lock | 145 | |
| f3 | 114 | semi-colon | 186 | |
| f4 | 115 | equal sign | 187 | |
| f5 | 116 | comma | 188 | |
| f6 | 117 | dash | 189 | |
| f7 | 118 | period | 190 | |
| f8 | 119 | forward slash | 191 | |
| f9 | 120 | grave accent | 192 | |
| f10 | 121 | open bracket | 219 | |
| f11 | 122 | back slash | 220 | |
| f12 | 123 | close braket | 221 | |
| single quote | 222 |
No comments:
Post a Comment