javascript - Simple key combo in jquery -
i'm looking catch simple key combos such ctrl + a. here's stab @ it:
var isctrl = false; $(window).keydown(function (e) { if (e.keycode == 17) isctrl = true; if (isctrl && e.keycode == 65) alert('hi'); });
is , robust approach? if not, how can improve on it?
since you're using jquery, try utilize library provides normalize keystrokes .ctrlkey , .which:
if (e.which == 17 && e.ctrlkey) alert('hi');
Comments
Post a Comment