jQuery also has a great implementation that is incredibly easy to use. Here you can implement this functionality in browsers:
$(document).keypress(function(e){ var checkWebkitandIE=(e.which==26 ? 1 : 0); var checkMoz=(e.which==122 && e.ctrlKey ? 1 : 0); if (checkWebkitandIE || checkMoz) $("body").append("<p>ctrl+z detected!</p>"); });
Tested in IE7, Firefox 3.6.3 and Chrome 4.1.249.1064
Another way to do this is to use the keydown event and track event.keyCode. However, since jQuery normalizes keyCode and charCode using event.which, their specification recommends using event.which in various situations:
$(document).keydown(function(e){ if (e.keyCode==90 && e.ctrlKey) $("body").append("<p>ctrl+z detected!</p>"); });
Trafalmadorian May 21 '10 at 1:45 a.m. 2010-05-21 01:45
source share