MousetrapをTypescriptで書き換える
code:test.ts
{
const trap = new Mousetrap("#text-input");
// single keys
trap.bind('4', function() { console.log('4'); });
trap.bind("?", function() { console.log('show shortcuts!'); });
trap.bind('esc', function() { console.log('escape'); }, 'keyup');
// combinations
trap.bind('command+shift+k', function() { console.log('command shift k'); });
// map multiple combinations to the same callback
console.log('command k or control k');
// return false to prevent default browser behavior
// and stop event from bubbling
return false;
});
// gmail style sequences
trap.bind('g i', function() { console.log('go to inbox'); });
trap.bind('* a', function() { console.log('select all'); });
// konami code!
trap.bind('up up down down left right left right b a enter', function() {
console.log('konami code');
});
}