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

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -