Skip to main content
Module

x/cliffy/examples/keypress/async_iterator_with_events.ts

Command line framework for deno 🦕 Including Commandline-Interfaces, Prompts, CLI-Table, Arguments Parser and more...
Extremely Popular
Go to Latest
File
#!/usr/bin/env -S deno run --unstable
import { keypress, KeyPressEvent } from "../../keypress/mod.ts";
keypress().addEventListener("keydown", (event: KeyPressEvent) => { console.log("# event"); if (event.ctrlKey && event.key === "x") { console.log("Canceled within event listener."); // Stop event loop and iterator. keypress().dispose(); }});
for await (const event of keypress()) { console.log("# iterator"); if (event.ctrlKey && event.key === "c") { console.log("Canceled within for loop."); // Stop event loop. keypress().dispose(); // Stop iterator. break; }}