I have a custom CMS and I would like to add a “shortcut menu” called by double-clicking Ctrlfor, say, 300 milliseconds. I am using a prototype, so my starting point is obviously this:
Event.observe(document, 'keypress', function(event) { if(event.keyCode == Event.KEY_XYZ) { show_shortcuts});
At the moment, my approach is to populate the global variable with the current time in milliseconds and check each time the key is pressed, whether the key was pressed less than 300 milliseconds ago.
But maybe there is a more elegant solution?
. , , - , Alt Shift. , , , .
var dblCtrlKey = 0; Event.observe(document, 'keydown', function(event) { if (dblCtrlKey != 0 && event.keyCode == 17) { alert("Ok double ctrl"); } else { dblCtrlKey = setTimeout('dblCtrlKey = 0;', 300); } });
Source: https://habr.com/ru/post/1722440/More articles:Size of ruby output text on rails - ruby | fooobar.comHow to enable scrollbars in silverlight 3.0 - c #How can I update a div continuously - jqueryЗачем нужны вторичные файлы данных в SQL Server? - sql-servereval during emacs lisp macro expansion - macrosGet LINQ to preload the full table - c #How to terminate the iPhone application? - iphoneCopying multiple records using foreign keys - mysqlCan I adjust (scale) only one component of the Android layout and update the layout during the animation - androidOracle REPLACE function - uncertainty about how to use for my script - stringAll Articles