如何读取 Ruby curses 应用程序中的箭头键?
How can I read the arrow keys in a Ruby curses application?
我有一个 Ruby curses 应用程序,我想在其中捕获箭头键和功能键。问题是某些击键在使用 STDIN.getch
时会生成多个值。当我键入 'regular' 键时,如 a-z
我得到一个单一的值。当我键入 [F] 键或箭头键时,我会返回三个值。
是否有 gem 设计用于处理键盘输入或更好的方法来完成阅读击键?
#!/usr/bin/ruby
require 'curses'
require 'io/console'
Curses.noecho
Curses.init_screen
main_window = Curses::Window.new(24, 40, 1, 0)
num_keys = 0
loop do
ch = STDIN.getch
num_keys = num_keys + 1
main_window.addstr(' key:' + ch.inspect + ' count:' + num_keys.to_s)
main_window.refresh
break if ch == 'q'
end
Curses.close_screen
我有一个 Ruby curses 应用程序,我想在其中捕获箭头键和功能键。问题是某些击键在使用 STDIN.getch
时会生成多个值。当我键入 'regular' 键时,如 a-z
我得到一个单一的值。当我键入 [F] 键或箭头键时,我会返回三个值。
是否有 gem 设计用于处理键盘输入或更好的方法来完成阅读击键?
#!/usr/bin/ruby
require 'curses'
require 'io/console'
Curses.noecho
Curses.init_screen
main_window = Curses::Window.new(24, 40, 1, 0)
num_keys = 0
loop do
ch = STDIN.getch
num_keys = num_keys + 1
main_window.addstr(' key:' + ch.inspect + ' count:' + num_keys.to_s)
main_window.refresh
break if ch == 'q'
end
Curses.close_screen