Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

instance method

IO#console_input_events

io.console_input_events([max_events], timeout: nil) → array

Reads up to max_events console input events, preserving their order. The default is one event. Blocks until at least one event is available, or for timeout seconds if specified. Returns an empty Array on timeout.

Each event is returned as a Hash. The :type and remaining keys are:

  • :key : :key_down, :repeat_count, :virtual_key_code, :virtual_scan_code, :unicode_char, and :control_key_state.

  • :mouse : :position ([row, column]), :button_state, :control_key_state, and :event_flags.

  • :window_buffer_size : :size ([rows, columns]).

  • :menu : :command_id.

  • :focus : :set_focus.

This method is Windows only.

You must require ‘io/console’ to use this method.