lua-users home
lua-l archive

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


Hi!

2010/12/22 Steve Litt <slitt@troubleshooters.com>:

> 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?

It's "Lua".

> [...]

> 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?

I quickly wrote a small module using curses, which uses this function:

static int lua_getch( lua_State *L ) {
    initscr();
    cbreak();
    int i = getch();
    lua_pushinteger( L, i );
    endwin();
    return 1;
}

(no error checking). Unfortunately, this clears the screen, which may
not be what you want to do. As this seems to be a common problem, I'd
be glad to hear of a solution.

On Windows, you can use _getch() from conio.h to do this (without
clearing the screen).

Regards,
Matthias