Deno.stdin raw map?

Does anyone have a map to which key is what raw buffer gotten from Deno.stdin? Like i can just search in a map, what key 27 represents? Also, i cant use stdin.setRaw(false) Code:
const stdin = Deno.stdin;
stdin.setRaw(true, {cbreak: Deno.build.os !== "windows"});

const maxBuffer = new Uint8Array(1024);
const read = async () => {
const size = await stdin.read(maxBuffer);
const buffer = maxBuffer.subarray(0, size || 0).toString();

Deno.writeTextFileSync("buffer.txt", buffer + "\n", {append: true});

setTimeout(read, 1000 / 60);
};

read();
const stdin = Deno.stdin;
stdin.setRaw(true, {cbreak: Deno.build.os !== "windows"});

const maxBuffer = new Uint8Array(1024);
const read = async () => {
const size = await stdin.read(maxBuffer);
const buffer = maxBuffer.subarray(0, size || 0).toString();

Deno.writeTextFileSync("buffer.txt", buffer + "\n", {append: true});

setTimeout(read, 1000 / 60);
};

read();
DAH
Deno AI Helper28d ago
I wasn't able to find the answer to your question in the official Deno documentation. However, looking at your message, I can provide some general advice based on the code snippet you've shared. Please note that this advice is not based on the Deno documentation, and you should double-check the accuracy of the advice given. In your code, you are using Deno.stdin to read raw input from the standard input. The raw buffer you receive will be a sequence of bytes, which may not directly correspond to the keys as you might expect from a character map. The value 27, for example, is often associated with the escape key (ESC) in ASCII, but interpreting raw input can be more complex, especially with multi-byte sequences for certain keys. Regarding the code snippet you've provided, it seems syntactically correct. However, there are a few things to consider: 1. You are using setTimeout to repeatedly call the read function. This is a non-blocking way to keep reading from stdin, but be aware that this creates a loop that will continue indefinitely unless you implement a condition to break out of it. 2. You are writing the buffer to a file named "buffer.txt" with each read. If you are trying to capture keypresses, this will work, but the file could grow quickly depending on how often keys are pressed. 3. The setRaw method is used correctly to enable raw mode, which is necessary to read keypresses as raw input. 4. The cbreak option is conditionally set based on the operating system, which is a good practice to handle differences between OSes. If you are looking for a map of raw key codes to their corresponding keys, you might need to refer to ASCII tables or terminal control sequences, which are not specific to Deno but rather to terminals and character encodings.
DAH
Deno AI Helper28d ago
For non-ASCII keys, this can be more complex as terminals can send multi-byte sequences. Remember that handling raw input can be quite complex, as it can involve interpreting control sequences, especially for special keys like arrow keys, function keys, etc. If you need to handle complex input, you might want to look for a library that can abstract away some of these details for you. Since you mentioned you cannot use stdin.setRaw(false), I assume you need to keep the raw mode enabled throughout your application's execution. If you encounter issues or need more specific behavior, you might need to look into more detailed documentation or resources on terminal input and control sequences.