Deno: Presses of special keys are not detectable by Deno on Windows

Created on 29 May 2020  路  2Comments  路  Source: denoland/deno

It is currently impossible to know when the user presses a special key in Console Window Host (the default terminal, conhost.exe) or Windows Terminal.

Here's a test script (needs --unstable because of Deno.setRaw()):

const stdinRid = Deno.stdin.rid;
if (Deno.isatty(stdinRid))
    Deno.setRaw(stdinRid, true);

(async () => {
    for await (const data of Deno.iter(Deno.stdin)) {
        if (data[0] === 0x03) // Ctrl+C
            Deno.exit();
        console.log(data);
    }
})();

This could log an escape sequence when the user presses, for example, the arrow keys (I think it does on Linux), but it logs nothing.

bug cli windows 馃棓

Most helpful comment

Any updates on that? Is there at least some workaround?

All 2 comments

@dd-pardal I get odd behavior from yours as well on Mac, have you tried:

if (!Deno.isatty(Deno.stdin.rid)) {
  console.log("Cannot do raw input when not tty");
  Deno.exit(-1);
}

Deno.setRaw(Deno.stdin.rid, true);

while (true) {
    const buf = new Uint8Array(512);
    const bytesRead = await Deno.read(Deno.stdin.rid, buf);
    console.log(bytesRead);
    console.log(buf);
    if (bytesRead === 1 && buf[0] === 0x03) {
        break;
    }
}

Deno.setRaw(Deno.stdin.rid, false);

Any updates on that? Is there at least some workaround?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

xueqingxiao picture xueqingxiao  路  3Comments

doutchnugget picture doutchnugget  路  3Comments

ry picture ry  路  3Comments

ry picture ry  路  3Comments

CruxCv picture CruxCv  路  3Comments