lua-users home
lua-l archive

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

On Fri, 29 Nov 2013 17:58:28 -0800
Paul Merrell <> wrote:

> On Fri, Nov 29, 2013 at 4:41 PM, Jose Torre-Bueno
> <> wrote:
> > Is there a way from inside Lua to check whether any key has been
> > pressed? will get a line from the console but if there is
> > no input it pends waiting for input.  I would like to be able to
> > write a test that gets input if any is ready but would continue if
> > there is none.  It is not obvious to me if this can be done at all.
> I don't think so. We had to implement in C the capability to read
> input from the system's keyboard buffer when we added AutoReplace and
> AutoCompletion features to NoteCase Pro.
> Paul

Hi Paul,

I've implemented Eric Raymond's way of reading keys raw, but a problem
I ran into was that it failed on a lot of Alt key combos and other key
combos and keystrokes. Can yours, for instance, discern between
Alt+Shift+Ctrl F10 and Alt+Shift+F10? If so, I'd like to see it.

By the way, to the original poster, if you're not too proud to kludge,
and if you're using this exclusively in Unix (I believe that includes
OS/x), I got this out of my umenu.lua, and it's been working for me for

function getch_unix()
        os.execute("stty cbreak </dev/tty >/dev/tty 2>&1")
        local key =
        os.execute("stty -cbreak </dev/tty >/dev/tty 2>&1");

The preceding code would need to be modified so it would return or
failure on the instead of blocking until a key was pressed.



Steve Litt                *
Troubleshooting Training  *  Human Performance