Keymaster.js:ホットキー用のシンプルなマイクロライブラリ

keymaster.jsライブラリがguthubに登場しました。これを使用して、キーボードショートカットを任意のページに追加できます。 もちろん、 jQuery Hotkeysモジュールは同じ目的のために設計されていますが、keymaster.jsには利点があります:このライブラリには依存関係がなく、非常に軽量で(60行のコードのみ)、既知のjQuery Hotkeysのバグがありません。 全体として、間違いなく有用なことです。



近い将来、keymaster.jsは別のINPUT / SELECT / TEXTAREAセレクターを追加します。これも便利な追加機能です。



key('c', 'issues', function(){ console.log('c/issues'); }); key('command+r, ctrl+r', 'issues', function(){ console.log('Hijacked Command+R or Ctrl+R, damn!'); return false; }); key('i', function(){ keyScope('issues'); console.log('Switched to "issues" scope. Command+R or Ctrl+R is now no longer reloading...'); }); key('i', function(){ console.log('(example of multiple assignment)'); }); key('o, enter, left', function(){ console.log('o, enter or left pressed!'); }); key('ctrl+c', function(){ console.log('this is not the command line'); }); key('⌘+right,shift+left,ctrl+shift+alt+d', function(event){ console.log('command+right, or shift+left, or ctrl+shift+alt+d'); console.log('here is the event: ', event); return false; // prevent default && stop propagation });
      
      





デモ



All Articles