Re: Console Application Keyboard event catch


#1

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


#2

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.