[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Console Application Keyboard event catch

Jano Svitok

7/2/2007 9:35:00 PM

On 7/2/07, marble.zhong@oocl.com <marble.zhong@oocl.com> wrote:
>
>
>
> Dear All,
>
> While doing the console application with Ruby, met below questions,
> please help, thanks in advance,
>
> 1. How to catch the Keyboard event, such as, how about the [TAB]
> key pressed, [CTRL] key and so on;
> 2. How to backdisplay the string? Such as, when you type [cd]
> command at the windows command mode, and press [TAB] it will help to
> complete the directory name, such as [abc] directory, once you press
> again, it will delete the [abc] directory and display another one, such
> as [efg].
>
> I try search from the google, but no result, please help thanks.

1. TAB is character #9, Ctrl+A is (IIRC) 0, Ctrl+B 1, etc. If you want
to catch all the combinations, you need to use special api, i.e. getch
from msvcrt, or curses.

2. BS (backspace, Ctrl+H) moves cursor one char left. CR (carriege
return, 13) moves cursor to the start of the line (you need to
overwrite everything you have written before, and it's possible that a
screen will scroll up, and LF (line feed) will be inserted by ruby)

3. have a look at readline library, it may do what you are trying to achieve.

J.