Jump to content

Help with ConsoleRead()

Recommended Posts


I'm not sure if this can actually be done.

I'd like to make a console application that outputs a prompt and then waits for user to input a single key and then acts on it while ignoring other keys (beep at the user if they are pressed), like choice.exe does in batch files.

I started out just trying to get ConsoleRead() to accept a single key press as input but I can't figure out how to get it to accept a key without the user pressing enter. The below (simplified) code captures the user input but it requires enter to be pressed.

Can single-key input read be done with ConsoleRead() as I describe?


$s_input = ""

ConsoleWrite("Input? ")

    $s_input = ConsoleRead()
    If @error Then ContinueLoop
    If @extended <> "" Then ExitLoop
Until $s_input <> ""



Share this post

Link to post
Share on other sites

I would suggest you use HotkeySet instead, or (if you want your hotkey response to be window-specific) embed your console in a gui (example, example) and use GUIsetAccelerators.

Edited by RTFC

Share this post

Link to post
Share on other sites

Thanks, RTFC. I'm doing this to help someone maintain some old batch files they want to re-use for a 64-bit Windows PE environment (where choice.exe has no direct replacement and using "set /p" requires the extra keypress of an enter key). My initial preference was to re-write the batch files with an AutoIT GUI but then I would be stuck maintaining them. :blink:

I will try to build something for them with HotKeySet if I can find the time, else they have to use "set /p" for now.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now