JavaScriptを使用したキーボードショートカット

Mousetrapは、キーボードのキーストロークを処理するための小さなライブラリ(1.4 KB)です。



// single keys Mousetrap.bind('4', function() { highlight(2); }); Mousetrap.bind("$", function() { highlight(3); }, 'keydown'); Mousetrap.bind('x', function() { highlight(4); }, 'keyup'); // combinations Mousetrap.bind('command+shift+K', function() { highlight(7); }); Mousetrap.bind(['command+k', 'ctrl+k'], function() { highlight(8); }); // gmail style sequences Mousetrap.bind('g i', function() { highlight(11); }); Mousetrap.bind('* a', function() { highlight(12)}); // konami code! Mousetrap.bind('up up down down left right left right ba enter', function() { highlight([15, 16, 17]); });
      
      





ご覧のとおり、シングルプレスとコンビネーションとキーボードコンボの両方がサポートされています。



Internet Explorer 6以降、Safari、Firefox、Chromeで動作します(Vimiumを有効にすると動作しません)。



試してみてください-craig.is/killing/mice



All Articles