kdog3682
kdog368210mo ago

Is there a deno function for inputting prompt reply without pressing enter?

Normally, one has to press enter for the input to be accepted. I was wondering if there was a version of prompt or confirm that lets you press a key, and that will automatically register (without pressing enter)
5 Replies
Deno AI Helper
Deno AI Helper10mo ago
I wasn't able to find the answer to your question in the official Deno documentation. Deno's standard library provides a prompt function which requires the user to press enter after typing their input. This is the typical behavior for console input in many environments. However, based on your message, it seems like you're looking for a way to capture a single keypress without the need to press enter. This kind of functionality usually involves more low-level handling of the terminal or command line interface and might not be directly supported by Deno's standard library. Please note that the advice provided here is not based on the Deno documentation, and I would advise you to double-check the accuracy of this advice. If you need this functionality, you might need to look into third-party libraries or modules that provide more advanced terminal handling capabilities, or you might need to write a custom solution that interfaces with the system's terminal directly.
NeTT
NeTT10mo ago
maybe you can check out deno.stdin?
Mqx
Mqx10mo ago
This would read one byte aka one letter at a time without pressing enter:
Deno.stdin.setRaw(true) // this is important
await Deno.stdin.readable.getReader().read().then(result => {
console.log(new TextDecoder().decode(result.value));
})
Deno.stdin.setRaw(true) // this is important
await Deno.stdin.readable.getReader().read().then(result => {
console.log(new TextDecoder().decode(result.value));
})
There are probably better ways to do this…
kdog3682
kdog3682OP10mo ago
Thanks! It works.
Mqx
Mqx10mo ago
:deno_thumbs_up:

Did you find this page helpful?