MousetrapをTypescriptで書き換える
Mousetrapをforkして書き換えて、キーを連続認識する仕組みを調べる
https://github.com/takker99/mousetrap/tree/typescript
https://scrapbox-bundler.vercel.app?url=https://scrapbox.io/api/code/takker/MousetrapをTypescriptで書き換える/test.ts&minify&bundle&run&reload
code:test.ts
import { Mousetrap } from "https://raw.githubusercontent.com/takker99/mousetrap/typescript/mod.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
trap.bind('command+k', 'ctrl+k', function() {
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');
});
}
#2023-11-01 13:51:23
#2023-05-30 05:51:28