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.
unknown (Guest)
on 2007-07-03 08: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
Jano S. (Guest)
on 2007-07-04 02:52
(Received via mailing list)
On 7/3/07, removed_email_address@domain.invalid 
<removed_email_address@domain.invalid> 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.