123456789_123456789_123456789_123456789_123456789_

Class: Reline::Windows::KeyEventRecord

Relationships & Source Files
Inherits: Object
Defined in: lib/reline/io/windows.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(virtual_key_code, char_code, control_key_state) ⇒ KeyEventRecord

[ GitHub ]

  
# File 'lib/reline/io/windows.rb', line 486

def initialize(virtual_key_code, char_code, control_key_state)
  @virtual_key_code = virtual_key_code
  @char_code = char_code
  @control_key_state = control_key_state
  @enhanced = control_key_state & ENHANCED_KEY != 0

  (@control_keys = []).tap do |control_keys|
    # symbols must be sorted to make comparison is easier later on
    control_keys << :ALT   if control_key_state & (LEFT_ALT_PRESSED | RIGHT_ALT_PRESSED) != 0
    control_keys << :CTRL  if control_key_state & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED) != 0
    control_keys << :SHIFT if control_key_state & SHIFT_PRESSED != 0
  end.freeze
end

Instance Attribute Details

#char_code (readonly)

[ GitHub ]

  
# File 'lib/reline/io/windows.rb', line 484

attr_reader :virtual_key_code, :char_code, :control_key_state, :control_keys

#control_key_state (readonly)

[ GitHub ]

  
# File 'lib/reline/io/windows.rb', line 484

attr_reader :virtual_key_code, :char_code, :control_key_state, :control_keys

#control_keys (readonly)

[ GitHub ]

  
# File 'lib/reline/io/windows.rb', line 484

attr_reader :virtual_key_code, :char_code, :control_key_state, :control_keys

#enhanced?Boolean (readonly)

[ GitHub ]

  
# File 'lib/reline/io/windows.rb', line 504

def enhanced?
  @enhanced
end

#virtual_key_code (readonly)

[ GitHub ]

  
# File 'lib/reline/io/windows.rb', line 484

attr_reader :virtual_key_code, :char_code, :control_key_state, :control_keys

Instance Method Details

#char

[ GitHub ]

  
# File 'lib/reline/io/windows.rb', line 500

def char
  @char_code.chr(Encoding::UTF_8)
end

#match?(control_keys: nil, virtual_key_code: nil, char_code: nil) ⇒ Boolean

Verifies if the arguments match with this key event. Nil arguments are ignored, but at least one must be passed as non-nil. To verify that no control keys were pressed, pass an empty array: control_keys: [].

Raises:

  • (ArgumentError)
[ GitHub ]

  
# File 'lib/reline/io/windows.rb', line 511

def match?(control_keys: nil, virtual_key_code: nil, char_code: nil)
  raise ArgumentError, 'No argument was passed to match key event' if control_keys.nil? && virtual_key_code.nil? && char_code.nil?

  (control_keys.nil? || [*control_keys].sort == @control_keys) &&
  (virtual_key_code.nil? || @virtual_key_code == virtual_key_code) &&
  (char_code.nil? || char_code == @char_code)
end