From: Eric Armstrong Date: 2006-08-01T12:51:52+09:00 Subject: Re: Loop Timing and Constant Input Picklegnome wrote: > > how can I get input from the keyboard without the user pressing enter? > For a platform independent operation, I recently began investigating "Curses": require 'curses' include Curses operations to play with: clear -- clear the screen addstr -- append text to the buffer refresh -- display the text in the buffer getch -- get a character (compare to ?x, for example, to test for the letter "x") I have a getting-started template, but neglected to push it to the web. Ask me again tomorrow... So far, I've found two problems with curses: a) There doesn't seem to be any equivalent for the windows Kbhit. That's the nice little operation that lets you ask whether there is a character in the buffer, and proceed if there isn't any. b) Examining the Curses API at http://www.ruby-doc.org/stdlib/, I found what can only be described as an embarassing lack of commentary. Not even one word! And since it's a wrapper, the implementation code is of no help. (And curses isn't even mentioned here: http://www.rubymanual.org/list/classes) I can only assume that some form of standard operational documentation exists on the web. If so the API doc should point to it, at least. (It's difficult to find, assuming it exists, because of all the references to NCURSES. That seems to be good, but the APIs are a wrapper for an ncurses.lib, which raises the ugly spectre of installation issues in my non-standard location. When I tried that with htree, I got horrible ".so" not found errors that no one could help with--so I abandoned htree for another day.) Searching on "curses API", I did find these papers: Curses in Python http://aspn.activestate.com/ASPN/docs/ActivePython/2.3/howto/curses/curses.html Tutorial on Python Curses Programming http://heather.cs.ucdavis.edu/~matloff/Python/PyCurses.pdf On my solaris box there is also man page for curses, but it lists dozens of APIs that aren't in the ruby library--and to find out what they do, you have to look them up individually. Still, *nix users have a way to find out what the APIs are expected to do. Windows users are SOL, unless someone can point me to a good man-page => html conversion tool. (The utility I wrote goes in the other direction, unfortunately.)