Page 1 of 1

Pause command like in Windows batch files

Posted: Mon Feb 24, 2025 11:02 pm
by Quin
This is a very small piece of code, but I needed it for an application so figured I'd share it here. It simulates something like the pause command in Windows batch scripts, which prompts the user with "Press any key to continue . . ." and halts the script until they press a key.

Code: Select all

Macro Pause
  PrintN("Press any key to continue . . .")
  Repeat
    Delay(10)
  Until Inkey() <> "" Or RawKey()
EndMacro

OpenConsole()
Pause
Enjoy :)

Re: Pause command like in Windows batch files

Posted: Tue Feb 25, 2025 12:57 am
by BarryG
Nice. :) But be aware that the Repeat/Until loop uses a lot of CPU (10% on my PC), so better to stick Delay(50) after Repeat to stop that. The keystroke will still respond immediately despite this, and the CPU drops to 0%, which is better.

Re: Pause command like in Windows batch files

Posted: Tue Feb 25, 2025 1:37 am
by Quin
Hi Barry,
Thanks for this! I haven't needed to write a loop like this in a few years, so this slipped my mind. Thanks for keeping me in shape :D
I did Delay(10). This is enough on my 16-core Ryzen and should hopefully be enough for all cases, let me know if you get other results, I'd be happy to tweak it if so. :)

Re: Pause command like in Windows batch files

Posted: Tue Feb 25, 2025 2:07 am
by Quin
This little bit of code is now in my ConsoleTools Module.