On Mon, Mar 21, 2011 at 1:33 PM, Sean Eskapp <eatingstap...@gmail.com> wrote:
> Is there a way to get a single keystroke in D2? Any method I've tried requires
> pushing Enter before the stroke is registered.
>

Hi Sean,

what you want to do is OS dependent.

I needed something similar ('press key to continue')

e.g.: for Windows

import core.sys.windows.windows;

bool kbHit() {
        // inspired by
http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1045691686&id=1043284392
        HANDLE stdIn = GetStdHandle(STD_INPUT_HANDLE);
        DWORD saveMode;

        GetConsoleMode(stdIn, &saveMode);
        SetConsoleMode(stdIn, ENABLE_PROCESSED_INPUT);

        bool ret = false;

        if (WaitForSingleObject(stdIn, INFINITE) == WAIT_OBJECT_0) {
                uint num;
                char ch;

                ReadConsoleA(stdIn, &ch, 1, &num, cast(void *) 0L);
                ret = true;
        }
        
        SetConsoleMode(stdIn, saveMode);
        return ret;
}

void wait_for_key() {
        writeln("\nPress any key to continue");
        while (!kbHit())
                {}
}


for Linux/Unix something like
http://www.linuxquestions.org/questions/programming-9/kbhit-34027/
should work.

Hope that helps,

Lars

Reply via email to