Class: Reline::Windows::KeyEventRecord
- Inherits:
-
Object
- Object
- Reline::Windows::KeyEventRecord
- Defined in:
- lib/reline/io/windows.rb
Instance Attribute Summary collapse
-
#char_code ⇒ Object
readonly
Returns the value of attribute char_code.
-
#control_key_state ⇒ Object
readonly
Returns the value of attribute control_key_state.
-
#control_keys ⇒ Object
readonly
Returns the value of attribute control_keys.
-
#virtual_key_code ⇒ Object
readonly
Returns the value of attribute virtual_key_code.
Instance Method Summary collapse
- #char ⇒ Object
- #enhanced? ⇒ Boolean
-
#initialize(virtual_key_code, char_code, control_key_state) ⇒ KeyEventRecord
constructor
A new instance of KeyEventRecord.
-
#matches?(control_keys: nil, virtual_key_code: nil, char_code: nil) ⇒ Boolean
Verifies if the arguments match with this key event.
Constructor Details
#initialize(virtual_key_code, char_code, control_key_state) ⇒ KeyEventRecord
Returns a new instance of KeyEventRecord.
479 480 481 482 483 484 485 486 487 488 489 490 491 |
# File 'lib/reline/io/windows.rb', line 479 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 ⇒ Object (readonly)
Returns the value of attribute char_code.
477 478 479 |
# File 'lib/reline/io/windows.rb', line 477 def char_code @char_code end |
#control_key_state ⇒ Object (readonly)
Returns the value of attribute control_key_state.
477 478 479 |
# File 'lib/reline/io/windows.rb', line 477 def control_key_state @control_key_state end |
#control_keys ⇒ Object (readonly)
Returns the value of attribute control_keys.
477 478 479 |
# File 'lib/reline/io/windows.rb', line 477 def control_keys @control_keys end |
#virtual_key_code ⇒ Object (readonly)
Returns the value of attribute virtual_key_code.
477 478 479 |
# File 'lib/reline/io/windows.rb', line 477 def virtual_key_code @virtual_key_code end |
Instance Method Details
#char ⇒ Object
493 494 495 |
# File 'lib/reline/io/windows.rb', line 493 def char @char_code.chr(Encoding::UTF_8) end |
#enhanced? ⇒ Boolean
497 498 499 |
# File 'lib/reline/io/windows.rb', line 497 def enhanced? @enhanced end |
#matches?(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: []`.
504 505 506 507 508 509 510 |
# File 'lib/reline/io/windows.rb', line 504 def matches?(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 |