Jano Svitok
7/3/2007 10:52:00 PM
On 7/3/07, marble.zhong@oocl.com <marble.zhong@oocl.com> wrote:
>
>
> Thanks Jano,
>
> Could make a sample for it? Or give me the related API? Thanks.
> And, want to catch the event, not only catch the what user input after
> press [Enter], thanks.
Hi,
this is how you can obtain pressed keys on windows:
require 'Win32API'
module Windows
module Keyboard
Getch = Win32API.new('crtdll', '_getch', 'V', 'L')
Kbhit = Win32API.new('crtdll', '_kbhit', 'V', 'L')
def getch
Getch.call
end
def kbhit
Kbhit.call
end
end
end
and this is how you can use readline library to prompt and provide completion:
require 'readline'
Readline.completion_proc = proc {|word| ['array', 'of', 'possible',
'completions']}
line = Readline.readline("prompt>", true) # true means history on
J.