This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author esrever_otua
Recipients
Date 2005-07-07.10:42:54
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
Logged In: YES 
user_id=567623

I am not an expert C coder (no surprise) however this simple
code I wrote will accept a line of input (including the \r\n
on the end) without echoing it back to the user:

#include <windows.h>

#define LINE_BUF 65536

char *getstr(){
    /*
     * OK, basically, we get a handle to STDIN, take a copy
of the
     * flags currently in force, set our own to prevent
screen echo,
     * do a read of the console that returns on '\r\n'
(included in
     * returned string), restore the original flags on
STDIN, and
     * finally returns the input string.
     *
     * This is basically a re-implementation of getch(), but
instead
     * of a single char, you get a whole string (with no
screen echo).
     *
     * For docs on functions called, see:
     *
http://msdn.microsoft.com/library/en-us/dllproc/base/console_functions.asp
     */
    HANDLE hstdin;
    DWORD read_chars, mode;
    char in_chars[LINE_BUF];
    hstdin = GetStdHandle(STD_INPUT_HANDLE);
    GetConsoleMode(hstdin,
                   &mode);
    SetConsoleMode(hstdin,
                   ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT);
    ReadConsole(hstdin,
                in_chars,
                LINE_BUF,
                &read_chars,
                NULL);
    SetConsoleMode(hstdin,
                   mode);
    return in_chars;
}

This code, when SWIG-ed to use with Python 2.4.1 works
perfectly.  The key is setting the flags on the console
handle to remove the ENABLE_ECHO_INPUT flag.  Also, if
ENABLE_LINE_INPUT is removed, theoretically the
ReadConsole() function should return after each typed character.

On *nix you can use unicode_start and loadkeys to input
unicode directly, including ALT+xxxx style input.

Regards,
D
History
Date User Action Args
2008-01-20 09:57:58adminlinkissue1233785 messages
2008-01-20 09:57:58admincreate