import { keypress } from "https://deno.land/x/cliffy@v1.0.0-rc.2/keypress/mod.ts";
Listens to keypress events.
Promise
import { keypress, KeyPressEvent } from "./mod.ts";
const event: KeyPressEvent = await keypress();
console.log(event);
Async Iterator
import { keypress, KeyPressEvent } from "./mod.ts";
console.log("Press ctrl+c to exit.");
for await (const event: KeyPressEvent of keypress()) {
console.log(event);
if (event.ctrlKey && event.key === "c") {
console.log("exit");
break;
}
}
Event Target
import { keypress, KeyPressEvent } from "./mod.ts";
keypress().addEventListener("keydown", (event: KeyPressEvent) => {
console.log(event);
if (event.ctrlKey && event.key === "c") {
console.log("exit");
keypress().dispose();
}
});