Detect double Ctrl keypress in JS
问题 I have a custom CMS and would like to add a "shortcuts menu" triggered by the pressing of the Ctrl key twice within, say, 300 milliseconds. I use prototype, so my starting point obviously is: Event.observe(document, 'keypress', function(event) { if(event.keyCode == Event.KEY_XYZ) { show_shortcuts}); My approach at the moment would be populating a global variable with the current time in milliseconds, and checking on each keypress whether a keypress has happened less than 300 milliseconds ago.