0

I have a script, and it has a little message. I want it to not do anything until the user presses enter. I tried this:

console.log("Welcome to the Roblox cursor backup script!\n This script will backup your current Roblox cursor and replace it with the old 2021 Roblox cursor.\n\n Please make sure you have a Roblox client closed. \n This script is prefixed at /Applications/Roblox.app, if you are non-admin please run the command with the --noadmin flag.\n\n Press enter to continue. \n\n ---------------------------------------------------------");
// if user presses enter in the terminal, continue
process.stdin.on('keypress', function (letter, key) {
    if (key.name === 'return') {
        console.log("User pressed enter/return, continuing...");
    } else{
        // pause the script until the user presses enter
        process.stdin.pause();
    }

});

However, the script instantly continues. How do I make it so that the script doesn't do anything until the user pressed enter/return?

Full source code: https://github.com/Link2Linc/Old-Roblox-Cursor/blob/master/main.ts

1 Answers1

3

You can simply take input from stdin Sample function :

function waitForKey(keyCode) {
    return new Promise(resolve => {
        process.stdin.on('data',function (chunk) {
            if (chunk[0] === keyCode) {
                resolve();
                process.stdin.pause();
            }
        });
    });
}

Now if you want to wait for enter key :

await waitForKey(10);
Harsh Kanjariya
  • 503
  • 5
  • 11
  • Top-level 'await' expressions are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', 'node16', or 'nodenext', and the 'target' option is set to 'es2017' or higher. – Lincoln Muller May 30 '22 at 15:07
  • Fixed that, it still doesn't work. I wrapped it in an async function, but it just does the same thing as before. Code: `if (process.platform === 'darwin' && process.argv[2] === '--revert') { revertDefaultCursorMac(); } else { console.log('No arguments passed, defaulting to new cursor'); welcomeMessage(); bringBackOldCursorMac(); }` Check the github link, just updated it now. – Lincoln Muller May 30 '22 at 15:12