Skip to main content
Module

x/cliffy/keypress/mod.ts>keypress

Command line framework for deno 🦕 Including Commandline-Interfaces, Prompts, CLI-Table, Arguments Parser and more...
Extremely Popular
Latest
function keypress
import { keypress } from "https://deno.land/x/cliffy@v1.0.0-rc.4/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();
  }
});