Double Keypress Detection Plugin For jQuery - double-keypress
File Size: | 3.37 KB |
---|---|
Views Total: | 1974 |
Last Update: | |
Publish Date: | |
Official Website: | Go to website |
License: | MIT |

double-keypress is a useful jQuery plugin which can be used to detect and handle Doube Keypress event in your webpage. Supports both keydown and keyup events.
See also:
- jQuery Plugin For Handling Double Tap Event - doubleTap
- jQuery Plugin For Double Click/Tap Detection - doubleTap
How to use it:
1. Put the main JavaScript file jquery.double-keypress.js
after jQuery library like this:
<script src="https://code.jquery.com/jquery-1.12.4.min.js" integrity="sha384-nvAa0+6Qg9clwYCGGPpDQLVpLNn0fRaROjHqs13t4Ggj3Ez50XnGQqc/r8MhnRDZ" crossorigin="anonymous"> </script> <script src="jquery.double-keypress.js"></script>
2. Specify the JavaScript event keycodes in the JavaScript. Visit the Keycode testing tool to get the JavaScript event keycode.
var keyCode = 17; // Ctrl
3. Trigger a function when the Ctrl key is double-pressed.
$(function(){ $('body').dbKeypress(keyCode, function(e){ alert('CTRL key was double-pressed'); }); });
4. Specify the trigger event.
$(function(){ $('body').dbKeypress(keyCode,{ eventType: 'keydown', // or 'keyup' callback: function(e){ alert('Ctrl key was double-pressed'); } }); });
5. Set the interval in milliseconds.
$(function(){ $('body').dbKeypress(keyCode,{ interval: 350, callback: function(e){ alert('Ctrl key was double-pressed'); } }); });
6. The plugin also supports multiple keys.
$(function(){ var keyCodes = [16, 17]; $('body').dbKeypress(keyCodes, function(e){ if(e.keyCode == 16) { alert('SHIFT key was double-pressed'); } else if(e.keyCode == 17) { alert('CTRL key was double-pressed'); } }); });
This awesome jQuery plugin is developed by SUKOHI. For more Advanced Usages, please check the demo page or visit the official website.