lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi all,

I want to ask the user to type a keystroke, and get that keystroke without the 
user needing to press Enter. How do I do that in LUA?

In Perl you do it like this:

sub getch_unix($)
        {
        my $nodeSession = shift;
        my($GETCH_STYLE) = $nodeSession->getAttribute('getch_style');
        $GETCH_STYLE = 1 unless defined ($GETCH_STYLE);
        my($key);
        if ($GETCH_STYLE)
                {
                system "stty cbreak </dev/tty >/dev/tty 2>&1";
                }
        else
                {
                system "stty", '-icanon', 'eol', "\001";
                }

        $key = getc(STDIN);

        if ($GETCH_STYLE)
                {
                system "stty -cbreak </dev/tty >/dev/tty 2>&1";
                }
        else
                {
                system "stty", 'icanon', 'eol', '^@'; # ASCII null
                }
        return($key);       
        }

For the time being I just need to do it in Linux/Unix/BSD, but it would be 
nice to know how to do it in Windows too. Anyone know?

Thanks

SteveT

Steve Litt
Recession Relief Package
http://www.recession-relief.US
Twitter: http://www.twitter.com/stevelitt