Forum: Ruby Re: Console Application Keyboard event catch

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ead9f9fe6f54ef99b17dbcf8a923d990?d=identicon&s=25 unknown (Guest)
on 2007-07-03 06:17
(Received via mailing list)
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.

Marble
97550977337c9f0a0e1a9553e55bfaa0?d=identicon&s=25 Jano Svitok (Guest)
on 2007-07-04 00:52
(Received via mailing list)
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.
This topic is locked and can not be replied to.